home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / MM3Tp.sea Folder / Made by Marksman / Sources / mm / mmCommonMM_Demo.p < prev    next >
Text File  |  1994-01-16  |  82KB  |  2,353 lines

  1. Unit mmCommonMM_Demo;
  2. {  mmCommonMM_Demo                         Common }
  3. {  Copyright © 1994 George R. Cossey }
  4.  
  5. {
  6.     Name:  mmCommonMM_Demo
  7.     Function:  Common for the Marksman™ specific code.
  8.     History: 1/16/94 Original by George Cossey
  9.  
  10. }
  11.  
  12.  
  13. interface
  14.  
  15.  uses
  16.   Printing,Folders,Sound;
  17.  
  18.  
  19. { ======================================================= }
  20. { ======================================================= }
  21.  
  22. const
  23.  
  24.     { User event definitions }
  25.     UserEvent_None                     = 0;            { No user events available }
  26.     UserEvent_Open_Window             = 1;            { Open Window or modeless dialog }
  27.     UserEvent_Close_Window             = 2;            { Close Window or modeless dialog }
  28.     UserEvent_Activate_Window         = 3;            { Activate Window or modeless dialog }
  29.     UserEvent_Deactivate_Window     = 4;            { Deactivate Window or modeless dialog }
  30.     { IDs 0 to 999 reserved for Marksman™, all others available for special use }
  31.  
  32. { Menu list resource IDs }
  33.     Res_Menu_Apple     = 512;            { Menu resource ID,  }
  34.     MItem_About_Demo     = 1;
  35.  
  36.     Res_Menu_File     = 513;            { Menu resource ID, File }
  37.     MItem_New     = 1;
  38.     MItem_Open     = 2;
  39.     MItem_Close     = 4;
  40.     MItem_Save     = 5;
  41.     MItem_Save_As     = 6;
  42.     MItem_Revert     = 7;
  43.     MItem_Page_Setup     = 9;
  44.     MItem_Print     = 10;
  45.     MItem_Quit     = 12;
  46.  
  47.     Res_Menu_Edit     = 514;            { Menu resource ID, Edit }
  48.     MItem_Undo     = 1;
  49.     MItem_Cut     = 3;
  50.     MItem_Copy     = 4;
  51.     MItem_Paste     = 5;
  52.     MItem_Clear     = 6;
  53.     MItem_Select_All     = 7;
  54.  
  55.     Res_Menu_Windows     = 515;            { Menu resource ID, Windows }
  56.     MItem_Alert     = 1;
  57.     MItem_Modal_Dialog     = 2;
  58.     MItem_Movable_Modal_D     = 3;
  59.     MItem_Modeless_Dialog     = 4;
  60.     MItem_Window     = 5;
  61.     MItem_Floating_window     = 6;
  62.  
  63.  
  64.  
  65. { Window resource IDs, also controls grouped with the appropiate window }
  66.  
  67. { Variables for the alert titled  "My Alert" }
  68.     ResA_My_Alert        = 257;            { Alert, My Alert }
  69.   ResA_Cancel    = 1;            { ...Button, Cancel }
  70.   ResA_OK2    = 2;            { ...Button, OK }
  71.   ResA_Alert_message    = 3;            { ...Static Text, Alert message }
  72.  
  73. { Variables for the Dialog titled  "My Movable Modal" }
  74.   ResD_My_Movable_Moda        = 259;            { Dialog, My Movable Modal }
  75.   ResD_OK4    = 1;            { ...Button, OK }
  76.   ResD_Cancel3    = 2;            { ...Button, Cancel }
  77.   sResD_List_of_things    = 533;            { ...List, List of things }
  78.  
  79. { Variables for the Dialog titled  "My Modeless" }
  80.   ResD_My_Modeless        = 260;            { Dialog, My Modeless }
  81.   ResD_OK5    = 1;            { ...Button, OK }
  82.   ResD_Cancel4    = 2;            { ...Button, Cancel }
  83.   ResD_The_Icon    = 5;            { ...Icon, The Icon }
  84.   ResD_N_The_Icon    = 256;
  85.   ResD_H_The_Icon    = 257;
  86.   ResD_My_Scroll_bar    = 4;            { ...ScrollBar, My Scroll bar }
  87.   ResD_Tool_palette    = 3;            { ...Palette, Tool palette }
  88.   ResD_N_Tool_palette    = 30004;
  89.   ResD_Message_on_rect    = 7;            { ...HotSpot, Message on rect }
  90.   sResD_Message_on_rect    = 538;
  91.   ResD_The_Sicn    = 6;            { ...Sicn, The Sicn }
  92.   ResD_N_The_Sicn    = 256;
  93.   ResD_H_The_Sicn    = 257;
  94.  
  95. { Variables for the Dialog titled  "My Modal" }
  96.   ResD_My_Modal        = 258;            { Dialog, My Modal }
  97.   ResD_Cancel2    = 1;            { ...Button, Cancel }
  98.   ResD_OK3    = 2;            { ...Button, OK }
  99.   ResD_Checkboxes    = 3;            { ...Checkbox, Checkboxes }
  100.   ResD_for_selections    = 4;            { ...Radio, for selections }
  101.   ResD_Radio_buttons    = 5;            { ...Radio, Radio buttons }
  102.   sResD_Static_Text6    = 530;            { ...Static Text, Static Text }
  103.   sResD_Static_Text5    = 525;            { ...Static Text, Static Text }
  104.   sResD_Static_Text4    = 524;            { ...Static Text, Static Text }
  105.   ResD_PopUp    = 6;            { ...Popup menu, PopUp }
  106.   mResD_PopUp    = 20;
  107.  
  108. { Variables for the Dialog titled  "About Demo" }
  109.   ResD_About_Demo        = 256;            { Dialog, About Demo }
  110.   ResD_OK    = 1;            { ...Button, OK }
  111.   ResD_Static_Text3    = 2;            { ...Static Text, Static Text }
  112.   sResD_Static_Text2    = 516;            { ...Static Text, Static Text }
  113.   sResD_Static_Text    = 515;            { ...Static Text, Static Text }
  114.  
  115. { Variables for the Window titled  "My basic window" }
  116.   ResW_My_basic_window    = 261;            { Window, My basic window }
  117.   ResC_Button    = 542;            { ...Button, Button }
  118.   ResC_Checkbox    = 543;            { ...Checkbox, Checkbox }
  119.   sResC_Static_Text    = 544;    { ...Static Text, Static Text }
  120.   sResC_Edit_Text    = 545;    { ...Edit Text, Edit Text }
  121.   ResC_Rect_hotspot2    = 550;            { ...HotSpot, Rect hotspot2 }
  122.   sResC_Rect_hotspot2    = 0;
  123.   ResC_Scroll_bar    = 552;            { ...ScrollBar, Scroll bar }
  124.   ResC_Icon    = 547;            { ...Icon, Icon }
  125.   ResC_N_Icon    = 258;
  126.   ResC_H_Icon    = 259;
  127.   ResC_Picture    = 546;            { ...Picture, Picture }
  128.   ResC_N_Picture    = 30001;
  129.   ResC_Tool_palette    = 549;            { ...Palette, Tool palette }
  130.   ResC_N_Tool_palette    = 30000;
  131.   ResC_Sicn    = 548;            { ...Sicn, Sicn }
  132.   ResC_N_Sicn    = 258;
  133.   ResC_H_Sicn    = 259;
  134.  
  135. { Variables for the Window titled  "Floating window" }
  136.   ResW_Floating_window    = 262;            { Window, Floating window }
  137.   ResC_Tool_palette2    = 553;            { ...Palette, Tool palette }
  138.   ResC_N_Tool_palette2    = 30000;
  139.  
  140.  
  141.  
  142. { ======================================================= }
  143.  
  144. type
  145.  
  146.     UserEventHRec = ^UserEventPRec;                 {Handle definition}
  147.     UserEventPRec = ^UserEventRec;                  {Pointer definition}
  148.     UserEventRec = record                           {User Event Record definition}
  149.             ID: integer;                             {ID for the type of user event}
  150.             ID2: integer;                           {Optionally used, 2nd ID, sometimes used}
  151.             Data1: longint;                         {Optionally used, Extra data}
  152.             Data2: longint;                         {Optionally used, Extra data}
  153.             theHandle: Handle;                         {Optionally used, Handle}
  154.             Next: UserEventHRec;                     {Handle of next event in the list}
  155.         end;
  156.  
  157.  
  158.     WindowLocRec = record                           { Window location record for Prefs }
  159.         Loc_My_Movable_Moda:Point;                    { Top Left corner of window }
  160.         Loc_My_Modeless:Point;                    { Top Left corner of window }
  161.         Loc_My_basic_window:Point;                    { Top Left corner of window }
  162.         Loc_Floating_window:Point;                    { Top Left corner of window }
  163.         Pad:integer;                                { Place holder for empty record }
  164.         end;
  165.  
  166.  
  167.     HasRec = record                               { Record for Gestalt checks }
  168.         ColorQD:Boolean;                        { Flag for Color QuickDraw being available }
  169.         FPU:Boolean;                            { Flag for Floating Point Math Chip being available }
  170.         AppleEvents:Boolean;                    { Whether AppleEvents are available }
  171.         AliasMgr:Boolean;                        { Whether AliasMgr is available }
  172.         EditionMgr:Boolean;                        { Whether EditionMgr is available }
  173.         NewStdFile:Boolean;                        { Whether HasNewStdFile is available }
  174.         PPCToolbox:Boolean;                        { Whether PPCToolbox is available }
  175.         QuickDraw32Bit:Boolean;                    { Whether 32Bit QuickDraw is available }
  176.         Gestalt:Boolean;                        { Whether Gestalt is available }
  177.         end;
  178.  
  179.  
  180.     FileRec = record                            { Record for reading and writing files }
  181.         typeList:SFTypeList;                    { For use in opening files }
  182.         Reply:SFReply;                            { For use in getting file names }
  183.         theStdFileReply:StandardFileReply;        { For use in getting file names }
  184.         inputRefNum:integer;                    { For the input file }
  185.         outputRefNum:integer;                    { For the output file }
  186.          inputFileName:Str255;                    { For the input file }
  187.          outputFileName:Str255;                    { For the output file }
  188.         end;
  189.  
  190.  
  191.     PrintingRec = record                        { Record for printing }
  192.         hPrint:THPrint;                            { Printer record }
  193.         PrinterIsOpen:Boolean;                    { Whether printer is open or not }
  194.         PageCount:integer;                        { For adding in page number }
  195.         LineCount:integer;                        { For printing }
  196.         PrinterVRes,PrinterHRes:integer;        { Printer resolution }
  197.         MaxPrintCharacters:integer;                { Max characters on one line }
  198.         MaxLines:integer;                        { Maximum lines in one page }
  199.         pPrPort:TPPrPort;                        { Printer port }
  200.         prStatus:TPrStatus;                        { Printing status }
  201.         CopyCount:integer;                        { Number of copies to do }
  202.         end;
  203.  
  204. { ======================================================= }
  205.  
  206. { Variables for the alert titled  "My Alert" }
  207.     My_AlertRec = record                { Record for Alert }
  208.         FirstTime:Boolean;                        { Flag for first time thru the filter }
  209.         Enable_Cancel:Boolean;            { ...Button global enable, Cancel }
  210.         Enable_OK2:Boolean;            { ...Button global enable, OK }
  211.         end;
  212.  
  213. { Variables for the dialog titled  "My Movable Modal" }
  214.     My_Movable_ModaRec = record                    { Record for dialog }
  215.         theDialog:DialogPtr;                        { Window pointer to this dialog }
  216.         ExitDialog:Boolean;                        { Flag to exit dialog }
  217.         Enable_OK4:Boolean;            { ...Button global enable, OK }
  218.         Enable_Cancel3:Boolean;            { ...Button global enable, Cancel }
  219.         List_List_of_things:ListHandle;            { ...List, List of things }
  220.         ListRect_List_of_things:Rect;
  221.         end;
  222.  
  223. { Variables for the dialog titled  "My Modeless" }
  224.     My_ModelessRec = record                    { Record for dialog }
  225.         theDialog:DialogPtr;                        { Window pointer to this dialog }
  226.         ExitDialog:Boolean;                        { Flag to exit dialog }
  227.         Enable_OK5:Boolean;            { ...Button global enable, OK }
  228.         Enable_Cancel4:Boolean;            { ...Button global enable, Cancel }
  229.         Enable_My_Scroll_bar:Boolean;            { ...ScrollBar global enable, My Scroll bar }
  230.         Value_My_Scroll_bar:integer;
  231.         Enable_The_Icon:Boolean;            { ...Icon button global enable, The Icon }
  232.         Enable_Tool_palette:Boolean;            { ...Palette global enable, Tool palette }
  233.         Value_Tool_palette:integer;
  234.         Enable_Message_on_rect:Boolean;            { ...HotSpot global enable, Message on rect }
  235.         Rect_Message_on_rect:Rect;
  236.         Enable_The_Sicn:Boolean;            { ...Sicn global enable, The Sicn }
  237.         end;
  238.  
  239. { Variables for the dialog titled  "My Modal" }
  240.     My_ModalRec = record                    { Record for dialog }
  241.         theDialog:DialogPtr;                        { Window pointer to this dialog }
  242.         ExitDialog:Boolean;                        { Flag to exit dialog }
  243.         Enable_Cancel2:Boolean;            { ...Button global enable, Cancel }
  244.         Enable_OK3:Boolean;            { ...Button global enable, OK }
  245.         Enable_Checkboxes:Boolean;            { ...Checkbox global enable, Checkboxes }
  246.         Value_Checkboxes:integer;
  247.         Enable_for_selections:Boolean;            { ...Radio global enable, for selections }
  248.         Value_for_selections:integer;
  249.         Enable_Radio_buttons:Boolean;            { ...Radio global enable, Radio buttons }
  250.         Value_Radio_buttons:integer;
  251.         Enable_PopUp:Boolean;            { ...Popup menu global enable, PopUp }
  252.         Value_PopUp:integer;
  253.         end;
  254.  
  255. { Variables for the dialog titled  "About Demo" }
  256.     About_DemoRec = record                    { Record for dialog }
  257.         theDialog:DialogPtr;                        { Window pointer to this dialog }
  258.         ExitDialog:Boolean;                        { Flag to exit dialog }
  259.         Enable_OK:Boolean;            { ...Button global enable, OK }
  260.         end;
  261.  
  262. { Variables for the window titled  "My basic window" }
  263.     My_basic_windowPRec = ^My_basic_windowRec;      {Pointer definition}
  264.     My_basic_windowRec = record                    { Record for dialog }
  265.         theWindow:WindowPtr;                        { Window pointer }
  266.         Next: My_basic_windowPRec;                 { Pointer of next in the list }
  267.         WindowBackColor:RGBColor;                    { Background window color }
  268.         Ctrl_Button:ControlHandle;            { ...Button, Button }
  269.         Enable_Button:Boolean;
  270.         Ctrl_Checkbox:ControlHandle;            { ...Checkbox, Checkbox }
  271.         Enable_Checkbox:Boolean;
  272.         Value_Checkbox:integer;
  273.         Ctrl_Scroll_bar:ControlHandle;            { ...ScrollBar, Scroll bar }
  274.         Enable_Scroll_bar:Boolean;
  275.         Value_Scroll_bar:integer;
  276.         Ctrl_Icon:ControlHandle;            { ...Icon button, Icon }
  277.         Enable_Icon:Boolean;
  278.         Ctrl_Picture:ControlHandle;            { ...Picture button, Picture }
  279.         Enable_Picture:Boolean;
  280.         TE_Edit_Text:TEHandle;                { ...Edit Text, Edit Text }
  281.         TEStr_Edit_Text:Str255;
  282.         TERect_Edit_Text:Rect;
  283.         Ctrl_Tool_palette:ControlHandle;            { ...Palette, Tool palette }
  284.         Enable_Tool_palette:Boolean;
  285.         Value_Tool_palette:integer;
  286.         Ctrl_Rect_hotspot2:ControlHandle;            { ...HotSpot, Rect hotspot2 }
  287.         Enable_Rect_hotspot2:Boolean;
  288.         Rect_Rect_hotspot2:Rect;
  289.         Ctrl_Sicn:ControlHandle;            { ...Sicn, Sicn }
  290.         Enable_Sicn:Boolean;
  291.         end;
  292.  
  293. { Variables for the window titled  "Floating window" }
  294.     Floating_windowPRec = ^Floating_windowRec;      {Pointer definition}
  295.     Floating_windowRec = record                    { Record for dialog }
  296.         theWindow:WindowPtr;                        { Window pointer }
  297.         Next: Floating_windowPRec;                 { Pointer of next in the list }
  298.         WindowBackColor:RGBColor;                    { Background window color }
  299.         Ctrl_Tool_palette2:ControlHandle;            { ...Palette, Tool palette }
  300.         Enable_Tool_palette2:Boolean;
  301.         Value_Tool_palette2:integer;
  302.         end;
  303.  
  304.  
  305. { ======================================================= }
  306. { ======================================================= }
  307.  
  308. var
  309.     UserEventList:UserEventHRec;            { User Event record list start }
  310.     myEvent:EventRecord;                    { Event record for all events }
  311.     WNE:Boolean;                            { WaitNextEvent trap is available }
  312.     SleepValue:integer;                        { Sleep value for Wait on events }
  313.     doneFlag:Boolean;                        { Exit program flag }
  314.     theInput:TEHandle;                        { Used in text edit selections }
  315.     cursorRgn:RgnHandle;                    { Cursor region for WaitNextEvent }
  316.     ReplyMode:integer;                        { Reply mode for AppleEvents }
  317.  
  318.     tempRect:Rect;                            { Temporary rect, not for long term use }
  319.     sTemp:Str255;                            { Temporary string, not for long term use }
  320.     tempChar:char;                            { Temporary use character }
  321.     LTemp:longint;                            { Temporary use long variable }
  322.     DType:integer;                            { Temporary use Type of dialog item }
  323.     DItem:Handle;                            { Temporary use Handle to the dialog item }
  324.     CItem:ControlHandle;                    { Temporary use Control handle }
  325.  
  326.     theWindowLocRec:WindowLocRec;
  327.  
  328.     Doing_MovableModal:Boolean;                { For Movable Modal dialogs }
  329.     HoldOffUserEvents:Boolean;                { Flag for holding off UserEvents }
  330.     InTheForeground:Boolean;                { Flag for running in MultiFinder foreground }
  331.  
  332.     Has:HasRec;                                { Gestalt check results }
  333.     Files:FileRec;                            { Reading and writing files }
  334.     Printing:PrintingRec;                    { Printing }
  335.  
  336.     Black_ForeColor,White_BackColor:RGBColor;{ Standard colors }
  337.  
  338.     Menu_Apple:MenuHandle;            { Menu handle,  }
  339.     Menu_File:MenuHandle;            { Menu handle, File }
  340.     Menu_Edit:MenuHandle;            { Menu handle, Edit }
  341.     Menu_Windows:MenuHandle;            { Menu handle, Windows }
  342.  
  343.  
  344.     Rec_My_Alert:My_AlertRec;    { Record for Alert, "My Alert" }
  345.     Rec_My_Movable_Moda:My_Movable_ModaRec;    { Record for dialog, "My Movable Modal" }
  346.     Rec_My_Modeless:My_ModelessRec;    { Record for dialog, "My Modeless" }
  347.     Rec_My_Modal:My_ModalRec;    { Record for dialog, "My Modal" }
  348.     Rec_About_Demo:About_DemoRec;    { Record for dialog, "About Demo" }
  349.     RecPtr_My_basic_window:My_basic_windowPRec;    { Record pointer for window, "My basic window" }
  350.     ListRecPtr_My_basic_window:My_basic_windowPRec;
  351.     MultipleAllowed_My_basic_window:Boolean;
  352.     RecPtr_Floating_window:Floating_windowPRec;    { Record pointer for window, "Floating window" }
  353.     ListRecPtr_Floating_window:Floating_windowPRec;
  354.     MultipleAllowed_Floating_window:Boolean;
  355.  
  356.  function Do_The_Open_File (NumberOfTypes: integer; var theVolRefNum: integer; fileFilter, dlgHook: ProcPtr): Boolean;
  357.  function Do_The_Select_Volume (var theFile: FSSpec): Boolean;        { Select a volume }
  358.  function Do_The_Save_File (creator, fileType: OSType; Prompt, DefaultName: Str255; var theVolRefNum, theRefNum: integer; dlgHook: ProcPtr): Boolean;
  359.  procedure Mk_ClearLayers;
  360.  function Mk_BehindWindow (theLayer: integer): WindowPtr;
  361.  procedure Mk_RegisterWindow (theWindowPtr: WindowPtr; theLayer: integer);
  362.  procedure Mk_HiliteWindow (theWindowPtr: WindowPtr);
  363.  procedure Mk_DragWindow (theWindowPtr: WindowPtr; where: Point; bounds: Rect);
  364.  function Mk_Is_FrontWindow (theWindowPtr: WindowPtr): Boolean;
  365.  procedure Mk_CloseLayeredWindow (theWindowPtr: WindowPtr);
  366.  procedure SetPreferences;
  367.  procedure GetPreferences;
  368.  procedure PositionWindow (theWindow: WindowPtr; WantLocation: Point; DefaultPosition: Point);
  369.  function CheckTrapAvailable (trapNumber: integer; tType: TrapType): Boolean;
  370.  procedure GetUserEvent (TheUserEvent: UserEventPRec);
  371.  procedure Add_UserEvent (ID1, ID2: integer; Data1, Data2: longint; theHandle: Handle);
  372.  procedure SetNameForPopup (theControl: ControlHandle);
  373.  procedure Add_List_String (theString: Str255; theList: ListHandle; var cSize: Point);
  374.  procedure Make_A_List (var theList: ListHandle; var theListRect: Rect; theWindow: WindowPtr; theStringResourceID: integer; theSize, theFont: integer; theStyle: Style; InDialog: Boolean);
  375.  procedure Play_The_Sound (ResID: integer);
  376.  procedure Get_TE_String (theTEArea: TEHandle; var theString: Str255);
  377.  procedure Make_TE_Area (var theTEArea: TEHandle; var Position: Rect; theFontSize, theFont, DefaultStringID: integer);
  378.  procedure Plot_Sicn (theSicnID: integer; Position: Rect);
  379.  procedure HandleWScrollBar (myPt: Point; code, Increment, LIncrement: integer; theControl: ControlHandle);
  380.  procedure PageSetup;
  381.  procedure PrintJobSetup;
  382.  procedure OpenThePrinter (var Cancelled: Boolean);
  383.  procedure CloseThePrinter;
  384.  procedure SetupTheItem (theDialog: DialogPtr; ItemID: integer; SizeIt, ShowIt, EnableIt, SetTheMax: Boolean; thePosition: Rect; ExtraData: longint; StringID: integer);
  385.  procedure CenterOnColorScreen (theWindow: WindowPtr);
  386.  procedure GetDeepestColorScreenRect (DeepRect: Rect);
  387.  procedure HiliteDefaultButton (theDialog: DialogPtr; theItem: integer);
  388.  procedure CheckKeysInDialog (theDialog: DialogPtr; var valMyFilter: Boolean; var theEvent: EventRecord; var itemHit: integer);
  389.  procedure SetupNormalControl (theDialog: DialogPtr; theItem: integer; Enabled: Boolean; InitialValue: integer);
  390.  procedure BasicSetup (theDialog: DialogPtr; theItem: integer; Enabled: Boolean; MessageResID: integer; var theCItem: ControlHandle);
  391.  procedure SetupHotSpot (theDialog: DialogPtr; theItem: integer; MakeHotSpot: Boolean; LineWidth, ShadowWidth: longint; MessageResID: integer; Enabled: Boolean);
  392.  procedure SetupPlugin (theDialog: DialogPtr; theItem: integer; Enabled: Boolean; NormalID, HilitedID: longint; MessageResID: integer);
  393.  procedure SetupMinMaxValue (theDialog: DialogPtr; theItem, min, max, value: integer);
  394.  procedure SetupPopupMenu (theDialog: DialogPtr; theItem: integer; Enabled: Boolean; theMenuID, value: integer);
  395.  procedure SetupPalette (theDialog: DialogPtr; theItem: integer; Enabled: Boolean; NumberRows, NumberCols, PalPictureID, HiliteMethod: longint);
  396.  procedure SetupIconSicn (theDialog: DialogPtr; theItem: integer; Enabled: Boolean; NormalID, HilitedID: longint);
  397.  procedure ClearTheRadio (theDialog: DialogPtr; theItem: integer; var value: integer);
  398.  procedure DrawStaticTextBox (ResID: integer; theRect: Rect; Justify, theSize, theFont: integer; theStyle: Style);
  399.  procedure DrawStaticLine (ResID, Left, Top, theSize, theFont: integer; theStyle: Style);
  400.  procedure DrawTheTEArea (theTERect: Rect; theTE: TEHandle; theSize, theFont: integer; theStyle: Style);
  401.  function MakeNormalControl (theWindow: WindowPtr; theResID: integer; Enabled: Boolean; InitialValue: integer): ControlHandle;
  402.  function MakeTheHotSpot (theWindow: WindowPtr; theResID: integer; MakeHotSpot: Boolean; LineWidth, ShadowWidth: longint; MessageResID: integer; Enabled: Boolean): ControlHandle;
  403.  function MakeIconSicn (theWindow: WindowPtr; theResID: integer; Enabled: Boolean; NormalID, HilitedID: longint): ControlHandle;
  404.  function MakePlugin (theWindow: WindowPtr; theResID: integer; Enabled: Boolean; NormalID, HilitedID: longint; MessageResID, InitialValue: integer): ControlHandle;
  405.  procedure MakeMinMaxValue (theControl: ControlHandle; min, max, value: integer);
  406.  function MakePopupMenu (theWindow: WindowPtr; theResID: integer; Enabled: Boolean; theMenuID, value: integer): ControlHandle;
  407.  procedure UpdateTheList (theRgn: RgnHandle; theList: ListHandle; theRect: Rect; theSize, theFont: integer; theStyle: Style; InDialog: Boolean);
  408.  procedure ClickInTheList (myPt: Point; modifiers: integer; theList: ListHandle; theSize, theFont: integer; theStyle: Style; InDialog: Boolean);
  409.  function MakePalette (theWindow: WindowPtr; theResID: integer; Enabled: Boolean; NumberRows, NumberCols, PalPictureID, HiliteMethod: longint): ControlHandle;
  410.  procedure Activate_TE_Area (InDialog: Boolean; myPt: Point; theTE: TEHandle; thetextSize, thetextFont: integer; textStyle: Style);
  411.  
  412. { ======================================================= }
  413. { ======================================================= }
  414.  
  415. implementation
  416.  
  417. { ======================================================= }
  418. { ======================================================= }
  419.  
  420. const
  421.     LowestWindowIndex        =    0;
  422.     HighestWindowIndex        =   10;
  423.     WindowList            = $000009D6;
  424. type
  425.   LongPtr = ^longint;
  426. var
  427.     TopMostWindows:array[0..12] of WindowPtr;
  428.     BottomMostWindows:array[0..12] of WindowPtr;
  429.  
  430.     { Variables used by Select Volume }
  431.     Last_vRefNum:integer;
  432.     Last_parID:integer;
  433.     Last_Name:Str255;
  434.  
  435. {In Main file, no parameters, it uses global myEvent}
  436.  procedure DoActivate;
  437.  External;
  438.  
  439. procedure U_GetPrefParams(var PrefCreator,PrefType:OSType;var thePrefsFilename:Str255;var PrefsRecSize:longint;var thePrefsFormatRevision:integer);
  440.  External;
  441.  
  442. procedure U_GetPreferences(thePrefsH:Handle);
  443.  External;
  444.  
  445. procedure U_ReadPrefsPrivate(PrefsRefNum:integer);
  446.  External;
  447.  
  448.  procedure U_SetPreferences (thePrefsH: Handle);
  449.  External;
  450.  
  451. { ======================================================= }
  452. { ======================================================= }
  453.  
  454. { Routine: Mk_ClearLayers }
  455. { Purpose: Init our arrays for layered windows }
  456.  
  457. procedure Mk_ClearLayers;
  458. var
  459.     Index:integer;
  460.  
  461.  
  462. begin
  463. for Index := LowestWindowIndex to HighestWindowIndex do
  464.    begin
  465.     TopMostWindows[Index] := nil;
  466.     BottomMostWindows[Index] := nil;
  467.    end;
  468. end;
  469.  
  470. { ======================================================= }
  471.  
  472. { Routine: VerifyWindowLayers }
  473. { Purpose: Verify all windows are at the proper layer }
  474.  
  475. procedure VerifyWindowLayers;
  476. var
  477.     Index,theLayer:integer;
  478.     theWindowPeek:WindowPeek;
  479.     theWindowListPtr: LongPtr;
  480.     theRefCon:longint;
  481.     theWindowPtr,theOutOfOrderWindowPtr:WindowPtr;
  482.     Out_Of_Place:Boolean;
  483.  
  484.  
  485. begin
  486. Out_Of_Place := true;
  487. while (Out_Of_Place) do
  488.    begin
  489.     Mk_ClearLayers;                                { Clear all arrays, we will refill them }
  490.     theOutOfOrderWindowPtr := nil;
  491.     Out_Of_Place := false;
  492.  
  493.     Index := HighestWindowIndex + 1;
  494.     theWindowListPtr := Pointer(WindowList);{ Get the window list start }
  495.     theWindowPeek := WindowPeek(theWindowListPtr^);    { Get the window list start }
  496.     while ((theWindowPeek <> nil) and (not(Out_Of_Place))) do
  497.            begin
  498.         if ((theWindowPeek^.visible) and (theWindowPeek^.windowKind = userKind)) then
  499.             begin
  500.             theWindowPtr := WindowPtr(theWindowPeek);{ Get the window pointer }
  501.  
  502.             theRefCon := GetWRefCon(theWindowPtr);
  503.             theRefCon := BAND(theRefCon,$FF000000);        { Mask off, to get the layer }
  504.                theLayer := BSR(theRefCon,24);                { Move into lower byte }
  505.             if (theLayer < LowestWindowIndex) then        { Pin at 0 }
  506.                 theLayer := LowestWindowIndex;
  507.             if (theLayer > HighestWindowIndex) then        { Pin at top }
  508.                 theLayer := HighestWindowIndex;
  509.             if (theLayer > Index) then
  510.                 begin
  511.                 Index := theLayer;
  512.                 Out_Of_Place := true;
  513.                 if (theOutOfOrderWindowPtr <> nil) then
  514.                     SendBehind(theOutOfOrderWindowPtr,theWindowPtr);
  515.                 end
  516.             else if (theLayer < Index) then
  517.                 begin
  518.                 Index := theLayer;
  519.                 TopMostWindows[theLayer] := theWindowPtr;
  520.                 BottomMostWindows[theLayer]  := theWindowPtr;
  521.                 end
  522.             else
  523.                 BottomMostWindows[theLayer]  := theWindowPtr;
  524.             theOutOfOrderWindowPtr := theWindowPtr;
  525.             end;
  526.         theWindowPeek := theWindowPeek^.nextWindow;{ Get the next window }
  527.         end;
  528.     end;
  529.  
  530. end;
  531.  
  532. { ======================================================= }
  533.  
  534. { Routine: Mk_BehindWindow }
  535. { Purpose: Get which window to place us behind }
  536.  
  537. function Mk_BehindWindow(theLayer:integer):WindowPtr;
  538. var
  539.     LayerIndex:integer;
  540.     ReturnWindowPtr:WindowPtr;
  541.  
  542.  
  543. begin
  544. ReturnWindowPtr := WindowPtr(-1);                    { Default to In front of everyone }
  545.  
  546. VerifyWindowLayers;                                { Make sure our tables are up to date }
  547.  
  548. LayerIndex := HighestWindowIndex;
  549. while ((LayerIndex > theLayer) and (LayerIndex >= LowestWindowIndex)) do
  550.    begin
  551.     if (BottomMostWindows[LayerIndex] <> nil) then
  552.         ReturnWindowPtr := BottomMostWindows[LayerIndex];
  553.     LayerIndex := LayerIndex - 1;
  554.     end;
  555.  
  556. Mk_BehindWindow := ReturnWindowPtr;
  557. end;
  558.  
  559. { ======================================================= }
  560.  
  561. { Routine: Mk_RegisterWindow }
  562. { Purpose: Place layer in RefCon and verify layers }
  563.  
  564. procedure Mk_RegisterWindow(theWindowPtr:WindowPtr;theLayer:integer);
  565. var
  566.     theRefCon:longint;
  567.     theLLayer:longint;
  568.  
  569.  
  570. begin
  571. theRefCon := GetWRefCon(theWindowPtr);                { Get the window refcon }
  572. theRefCon := BAND(theRefCon,$00FFFFFF);                { Mask off, in case something else is there }
  573. theLLayer := theLayer;                                { Get the window layer }
  574. theLLayer := BSL(theLLayer, 24);                    { Move into upper byte }
  575. theRefCon := BOR(theRefCon,theLLayer);                { Mask layer into refcon }
  576. SetWRefCon(theWindowPtr,theRefCon);                    { Set the new refcon }
  577.  
  578. VerifyWindowLayers;                                    { Make sure our tables are up to date }
  579. end;
  580.  
  581. { ======================================================= }
  582.  
  583. { Routine: Mk_HiliteWindow }
  584. { Purpose: Hilite our layered window }
  585.  
  586. procedure Mk_HiliteWindow(theWindowPtr:WindowPtr);
  587. var
  588.     theWindowPeek:WindowPeek;
  589.     theWindowListPtr: LongPtr;
  590.     WasHilighted,CkHilighted,BehindWindow:WindowPtr;
  591.     theRefCon:longint;
  592.     theLayer,theWasLayer:integer;
  593.  
  594.  
  595. begin
  596. VerifyWindowLayers;                                { Make sure our tables are up to date }
  597.  
  598. theRefCon := GetWRefCon(theWindowPtr);
  599. theRefCon := BAND($FF000000,theRefCon);                    { Mask for top byte }
  600. theLayer := BSR(theRefCon, 24);                        { Move into lower byte }
  601. if (theLayer < LowestWindowIndex) then                    { Pin at 0 }
  602.     theLayer := LowestWindowIndex;
  603. if (theLayer > HighestWindowIndex) then                    { Pin at top }
  604.     theLayer := HighestWindowIndex;
  605.  
  606. theWindowListPtr := Pointer(WindowList);    { Get the window list start }
  607. theWindowPeek := WindowPeek(theWindowListPtr^);        { Get the window list start }
  608. WasHilighted := nil;
  609. while (theWindowPeek <> nil) do
  610.    begin
  611.     if ((theWindowPeek^.visible) and (theWindowPeek^.windowKind = userKind)) then
  612.         begin
  613.         if (theWindowPeek^.hilited) then
  614.             begin
  615.              CkHilighted := WindowPtr(theWindowPeek);
  616.             theRefCon := GetWRefCon(CkHilighted);
  617.             theRefCon := BAND($FF000000,theRefCon);        { Mask for top byte }
  618.              theWasLayer := BSR(theRefCon, 24);{ Move into lower byte }
  619.             if (theWasLayer = theLayer) then
  620.                 WasHilighted := CkHilighted;
  621.             end;
  622.         end;
  623.     theWindowPeek := theWindowPeek^.nextWindow;
  624.     end;
  625.  
  626. if (theWindowPtr <> WasHilighted) then
  627.     begin
  628.     if (WasHilighted <> nil) then
  629.         begin
  630.         theRefCon := GetWRefCon(WasHilighted);
  631.         theRefCon := BAND($FF000000,theRefCon);            { Mask for top byte }
  632.              theWasLayer := BSR(theRefCon, 24);{ Move into lower byte }
  633.         if (theWasLayer < LowestWindowIndex) then        { Pin at 0 }
  634.             theWasLayer := LowestWindowIndex;
  635.         if (theWasLayer > HighestWindowIndex) then        { Pin at top }
  636.             theWasLayer := HighestWindowIndex;
  637.         if (theWasLayer = theLayer) then
  638.             begin
  639.             HiliteWindow(WasHilighted, false);
  640.             myEvent.message := longint(WasHilighted);
  641.             myEvent.modifiers := 0;
  642.             DoActivate;                            { Deactivate, do links }
  643.             end;
  644.         end;
  645.  
  646.     HiliteWindow(theWindowPtr,true);
  647.     myEvent.message := longint(theWindowPtr);
  648.     myEvent.modifiers := 1;
  649.     DoActivate;                                    { Activate, do links }
  650.  
  651.     BehindWindow := Mk_BehindWindow(theLayer);        { Move to correct layer on the screen }
  652.     if (longint(BehindWindow) = -1) then
  653.         BringToFront(theWindowPtr)
  654.     else
  655.         SendBehind(theWindowPtr,BehindWindow);
  656.  
  657.     TopMostWindows[theLayer] := theWindowPtr;
  658.     end;
  659.  
  660. end;
  661.  
  662. { ======================================================= }
  663.  
  664. { Routine: Mk_DragWindow }
  665. { Purpose: Drag our layered window }
  666.  
  667. procedure Mk_DragWindow(theWindowPtr:WindowPtr;where:Point;bounds:Rect);
  668. var
  669.     savePort:GrafPtr;
  670.     WMgrPort:CGrafPtr;
  671.     hRegion,dragRgn:RgnHandle;
  672.     theWindowPeek:WindowPeek;
  673.     result:longint;
  674.     Horz,Vert:integer;
  675.     theCWindowPtr:CWindowPtr;
  676.     portBounds:Rect;
  677.     thePixMapHandle:PixMapHandle;
  678.  
  679.  
  680. begin
  681. if (WaitMouseUp) then
  682.     begin
  683.     theWindowPeek := WindowPeek(theWindowPtr);
  684.     theCWindowPtr := CWindowPtr(theWindowPtr);
  685.  
  686.     GetPort(savePort);
  687.     if (Has.ColorQD) then
  688.         GetCWMgrPort(WMgrPort)
  689.     else
  690.         GetWMgrPort(GrafPtr(WMgrPort));
  691.     SetPort(GrafPtr(WMgrPort));
  692.     hRegion := GetGrayRgn;
  693.     SetClip(hRegion);
  694.  
  695.     ClipAbove(theWindowPeek);
  696.  
  697.     dragRgn := NewRgn;
  698.     CopyRgn(theWindowPeek^.strucRgn, dragRgn);
  699.  
  700.     result := DragGrayRgn(dragRgn, where, bounds, bounds, 0, nil);
  701.     Horz := LoWord(result);
  702.     Vert := HiWord(result);
  703.  
  704.     if (Vert <> $8000) then
  705.         begin
  706.         if (BAND(theCWindowPtr^.portVersion,$C000) <> 0) then
  707.             begin
  708.             thePixMapHandle := theCWindowPtr^.portPixMap;
  709.             portBounds := thePixMapHandle^^.bounds;
  710.             end
  711.         else
  712.             portBounds := theWindowPtr^.portBits.bounds;
  713.  
  714.         Horz := Horz + (theWindowPtr^.portRect.left - portBounds.left);
  715.         Vert := Vert + (theWindowPtr^.portRect.top - portBounds.top);
  716.  
  717.         MoveWindow(theWindowPtr, Horz, Vert, false);
  718.         end;
  719.  
  720.     DisposeRgn(dragRgn);
  721.     SetPort(savePort);
  722.     end;
  723.  
  724. end;
  725.  
  726. { ======================================================= }
  727.  
  728. { Routine: Mk_Is_FrontWindow }
  729. { Purpose: Get the front window }
  730.  
  731. function Mk_Is_FrontWindow(theWindowPtr:WindowPtr):Boolean;
  732. var
  733.     IsFront:Boolean;
  734.     Index:integer;
  735.  
  736.  
  737. begin
  738. IsFront := false;
  739. for Index := LowestWindowIndex to HighestWindowIndex do
  740.     begin
  741.     if (TopMostWindows[Index] = theWindowPtr) then
  742.         IsFront := true;
  743.     end;
  744.  
  745. Mk_Is_FrontWindow := IsFront;
  746. end;
  747.  
  748. { ======================================================= }
  749.  
  750. { Routine: Mk_CloseLayeredWindow }
  751. { Purpose: Close a layered window }
  752.  
  753. procedure Mk_CloseLayeredWindow(theWindowPtr:WindowPtr);
  754. var
  755.     Index:integer;
  756.  
  757.  
  758.  
  759. begin
  760. for Index := LowestWindowIndex to HighestWindowIndex do
  761.     begin
  762.     if (TopMostWindows[Index] = theWindowPtr) then
  763.         TopMostWindows[Index] := nil;
  764.     if (BottomMostWindows[Index] = theWindowPtr) then
  765.         BottomMostWindows[Index] := nil;
  766.     end;
  767. VerifyWindowLayers;                                { Make sure our tables are up to date }
  768. end;
  769.  
  770. { ======================================================= }
  771.  
  772.  
  773. { ======================================================= }
  774.  
  775. { Routine: SetPreferences }
  776. { Purpose: Set new preferences }
  777.  
  778. procedure SetPreferences;
  779. var
  780.     thePrefsFilename:Str255;
  781.     theError:OSErr;
  782.     result,foundDirID,count,PrefsRecSize:longint;
  783.     foundVRefNum,PrefsRefNum,thePrefsFormatRevision:integer;
  784.     PrefsHandle:Handle;
  785.     HasFindFolder:Boolean;
  786.     PrefsFSSpec:FSSpec;
  787.     PrefCreator,PrefType:OSType;
  788.     theEnv:SysEnvRec;
  789.  
  790.  
  791. begin
  792. { Get parameters to use }
  793. U_GetPrefParams(PrefCreator,PrefType,thePrefsFilename,PrefsRecSize,thePrefsFormatRevision);
  794. PrefsRefNum := 0;
  795.  
  796. PrefsHandle := NewHandleClear(PrefsRecSize);            { Allocate the prefs space holder }
  797.  
  798. if (PrefsHandle <> nil) then
  799.     begin
  800.     HLock(PrefsHandle);                                { Lock for safety }
  801.  
  802.     U_SetPreferences(PrefsHandle);                    { Let the user set the other pref values }
  803.  
  804.     HasFindFolder := false;
  805.     if (Has.Gestalt) then                                { Must have Gestalt }
  806.         begin
  807.         theError := Gestalt(gestaltFindFolderAttr, result);{ Need FindFolder }
  808.         if ((theError = 0) and (BAND(result, BSL($00000001, gestaltFindFolderPresent)) <> 0)) then
  809.             HasFindFolder := true;
  810.  
  811.         if (HasFindFolder) then                            { Must have FindFolder }
  812.             begin
  813.             theError := FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,foundVRefNum,foundDirID);
  814.             if (theError = 0) then
  815.                 begin
  816.                 theError := FSMakeFSSpec(foundVRefNum,foundDirID,thePrefsFilename,PrefsFSSpec);
  817.                 if (theError = fnfErr) then                { File not found }
  818.                     theError := FSpCreate(PrefsFSSpec,PrefCreator,PrefType,0);{ Create the file }
  819.                 theError := FSpOpenDF(PrefsFSSpec,fsRdWrPerm,PrefsRefNum);{ Open the file }
  820.                 end;
  821.             end
  822.         else
  823.             begin
  824.             theError := SysEnvirons(1,theEnv);        { Get volume environs }
  825.             theError := FSOpen(thePrefsFilename,theEnv.sysVRefNum,PrefsRefNum);{ Open the file }
  826.             if (theError = fnfErr) then                { File not found }
  827.                 begin
  828.                 theError := Create(thePrefsFilename,theEnv.sysVRefNum,PrefCreator,PrefType);{ Create the file }
  829.                 theError := FSOpen(thePrefsFilename,theEnv.sysVRefNum,PrefsRefNum);{ Open the file }
  830.                 end;
  831.             end;
  832.  
  833.         if (theError = 0) then
  834.             begin
  835.             count := PrefsRecSize;
  836.             theError := FSWrite(PrefsRefNum,count,PrefsHandle^);{ Write new prefs }
  837.             theError := SetEOF(PrefsRefNum,count);    { Reset EOF }
  838.  
  839.             if (PrefsRefNum <> 0) then
  840.                 theError := FSClose(PrefsRefNum);    { Close file }
  841.  
  842.             HUnlock(PrefsHandle);
  843.             DisposeHandle(PrefsHandle);                { Done with Prefs handle }
  844.             end;
  845.         end;
  846.     end;
  847.  
  848. end;
  849.  
  850. { ======================================================= }
  851.  
  852. { Routine: GetPreferences }
  853. { Purpose: Get the preferences }
  854.  
  855. procedure GetPreferences;
  856. var
  857.     foundVRefNum,PrefsRefNum,FormatRevision,thePrefsFormatRevision:integer;
  858.     result,foundDirID,DataSize,count,PrefsRecSize:longint;
  859.     theError:OSErr;
  860.     GotPreferences,HasFindFolder:Boolean;
  861.     thePrefsFilename:Str255;
  862.     PrefsHandle:Handle;
  863.     PrefsFSSpec:FSSpec;
  864.     PrefCreator,PrefType:OSType;
  865.     theEnv:SysEnvRec;
  866.  
  867.  
  868. begin
  869. { Get parameters to use }
  870. U_GetPrefParams(PrefCreator,PrefType,thePrefsFilename,PrefsRecSize,thePrefsFormatRevision);
  871.  
  872. GotPreferences := false;                                { No prefs yet }
  873. HasFindFolder := false;                                { No FindFolder routine avail yet }
  874. PrefsRefNum := 0;                                    { No prefs file yet }
  875.  
  876. if (Has.Gestalt) then                                    { Must have Gestalt }
  877.     begin
  878.     theError := Gestalt(gestaltFindFolderAttr,result);{ Need FindFolder }
  879.     if ((theError = 0) and (BAND(result, BSL($00000001, gestaltFindFolderPresent)) <> 0)) then
  880.      HasFindFolder := true;
  881.  
  882.     if (HasFindFolder) then                                { Must have FindFolder }
  883.         begin
  884.         theError := FindFolder(kOnSystemDisk,kPreferencesFolderType,kCreateFolder,foundVRefNum,foundDirID);{ Get preference folder }
  885.         if (theError = noErr) then
  886.             begin
  887.             theError := FSMakeFSSpec(foundVRefNum,foundDirID,thePrefsFilename,PrefsFSSpec);
  888.             if (theError = fnfErr) then                    { File not found }
  889.                 theError := FSpCreate(PrefsFSSpec,PrefCreator,PrefType,0);{ Create the file }
  890.             theError := FSpOpenDF(PrefsFSSpec,fsRdWrPerm,PrefsRefNum);{ Open the file }
  891.             end;
  892.         end
  893.     else
  894.         begin
  895.         theError := SysEnvirons(1,theEnv);            { Get volume environs }
  896.         theError := FSOpen(thePrefsFilename,theEnv.sysVRefNum,PrefsRefNum);{ Open the file }
  897.         if (theError = fnfErr)    then                    { File not found }
  898.             begin
  899.             theError := Create(thePrefsFilename,theEnv.sysVRefNum,PrefCreator,PrefType);{ Create the file }
  900.             theError := FSOpen(thePrefsFilename,theEnv.sysVRefNum,PrefsRefNum);{ Open the file }
  901.             end;
  902.         end;
  903.  
  904.     if (theError = 0) then
  905.         begin
  906.         theError := GetEOF(PrefsRefNum,DataSize);    { See if data in the file }
  907.         if (DataSize > 0) then                            { Must have data in the file to go on }
  908.             begin
  909.             count := 2;                                { Revision number size }
  910.             theError := FSRead(PrefsRefNum, count, Pointer(Ord(@FormatRevision)));{ Get revision number }
  911.             theError := SetFPos(PrefsRefNum,fsFromStart,0);{ Beginning again }
  912.  
  913.             if ((FormatRevision = thePrefsFormatRevision) and (PrefsRecSize > 0)) then{ Only do if up to date revision }
  914.                 begin
  915.                 PrefsHandle := NewHandleClear(PrefsRecSize);{ Get space for the prefs }
  916.                 if (PrefsHandle <> nil)    then            { Make sure we got our little tiny handle }
  917.                     begin
  918.                     HLock(PrefsHandle);                { Lock this for safety }
  919.                     count := PrefsRecSize;            { See how much data to read }
  920.                     theError := FSRead(PrefsRefNum,count,PrefsHandle^);{ Read it on in }
  921.                     if (theError = 0) then
  922.                         U_GetPreferences(PrefsHandle);{ Let the user get the prefs }
  923.  
  924.                     GotPreferences := true;            { Got our preferences }
  925.                     HUnlock(PrefsHandle);            { OK to unlock now }
  926.                     DisposeHandle(PrefsHandle);        { All done with this record  }
  927.                     end;
  928.                 end
  929.             else
  930.                 U_ReadPrefsPrivate(PrefsRefNum);    { Let the user read the prefs himself }
  931.             end;
  932.         if (PrefsRefNum <> 0) then                        { Done with the file , close it }
  933.             theError := FSClose(PrefsRefNum);
  934.         end;
  935.     end;
  936.  
  937. if (not(GotPreferences)) then                        { If we did not get prefs , use default values }
  938.     SetPreferences;                                { Set the default values }
  939.  
  940. end;
  941.  
  942. { ======================================================= }
  943.  
  944. procedure PositionWindow(theWindow:WindowPtr;WantLocation:Point;DefaultPosition:Point);
  945. var
  946.     FitsOK:Boolean;
  947.     WindowRect:Rect;
  948.     theDesktopPort:GrafPtr;
  949.     theRgn,the2Rgn:RgnHandle;
  950.  
  951.  
  952. begin
  953. FitsOK := false;                                        {Init to not on current screen(s) }
  954. WindowRect := theWindow^.portRect;                    { Save the rect to get the size }
  955. OffsetRect(WindowRect,-WindowRect.left,-WindowRect.top);    { Offset to 0,0 }
  956. OffsetRect(WindowRect,WantLocation.h,WantLocation.v);        { Offset to wanted location }
  957.  
  958. GetWMgrPort(theDesktopPort);                        { Get the screen }
  959.  
  960. theRgn := NewRgn;                                    { Make temp regions }
  961. the2Rgn := NewRgn;
  962. RectRgn(theRgn,WindowRect);                        { First region to our window rectangle on the screen }
  963. SectRgn(theRgn,theDesktopPort^.visRgn,the2Rgn);        { Do the intersection with the screen and window }
  964. if (EqualRgn(theRgn,the2Rgn)) then                        { If all of window in the screen area then ... }
  965.     FitsOK := true;                                    { ...all of the window is on the screen area }
  966.  
  967. DisposeRgn(theRgn);                                    { Dispose of temp regions }
  968. DisposeRgn(the2Rgn);
  969. if ((FitsOK) and ((WantLocation.h <> 0) or (WantLocation.v <> 0))) then        { If all of window in the screen area then ... }
  970.     MoveWindow(theWindow,WantLocation.h,WantLocation.v,false)    { Move to saved location }
  971. else
  972.     MoveWindow(theWindow,DefaultPosition.h,DefaultPosition.v,false); { Move to original location }
  973. end;
  974.  
  975. { ======================================================= }
  976.  
  977. { Routine: CheckTrapAvailable }
  978. { Purpose: See if trap is available, non-available traps all have a unique address }
  979.  
  980.  function CheckTrapAvailable (trapNumber: integer; tType: TrapType): Boolean; { See if a trap is available }
  981.   const
  982.    UnimplementedTrapNumber = $A89F;
  983.     { Unimplemented trap number }
  984.  
  985.  
  986.  begin
  987. { Check the two traps }
  988.   CheckTrapAvailable := (NGetTrapAddress(trapNumber, tType) <> GetTrapAddress(UnimplementedTrapNumber));{Check the two traps}
  989.  end;
  990.  
  991. { ======================================================= }
  992.  
  993. { Routine: GetUserEvent }
  994. { Purpose: See if any user events are available }
  995.  
  996. procedure GetUserEvent(TheUserEvent:UserEventPRec);
  997. var
  998.     NextUserEvent:UserEventHRec;                    { The next user event }
  999.  
  1000.  
  1001. begin 
  1002. TheUserEvent^.ID := UserEvent_None;                    { Set ID to no events are available }
  1003. if (UserEventList <> NIL) then                        { Get first entry in the list }
  1004.     begin
  1005.     HLock(Handle(UserEventList));                    { Lock for safety }
  1006.     TheUserEvent^.ID := UserEventList^^.ID;            { The event ID }
  1007.     TheUserEvent^.ID2 := UserEventList^^.ID2;        { The optional ID }
  1008.     TheUserEvent^.Data1 := UserEventList^^.Data1;    { The optional data }
  1009.     TheUserEvent^.Data2 := UserEventList^^.Data2;    { The optional data }
  1010.     TheUserEvent^.theHandle := UserEventList^^.theHandle;{ The optional handle }
  1011.     NextUserEvent := UserEventList^^.Next;            { The next list }
  1012.  
  1013.     DisposHandle(Handle(UserEventList));            { Remove this list item }
  1014.     UserEventList := NextUserEvent;                    { Make the next item the new first item }
  1015.     end;
  1016. end;
  1017.  
  1018. { ======================================================= }
  1019.  
  1020. { Routine: Add_UserEvent }
  1021. { Purpose: Add a user event }
  1022.  
  1023. procedure Add_UserEvent(ID1,ID2:integer;Data1,Data2:longint;theHandle:Handle);
  1024. var
  1025.     NewUserEvent:UserEventHRec;                        { The new user event }
  1026.     theUserEvent:UserEventHRec;                        { The user event }
  1027.  
  1028.  
  1029. begin 
  1030. NewUserEvent := UserEventHRec(NewHandle(sizeof(UserEventRec)));{ Allocate a record }
  1031. if (NewUserEvent <> NIL) then                        { Only do if we got the new record }
  1032.     begin
  1033.     HLock(Handle(NewUserEvent));                    { Lock for safety }
  1034.     NewUserEvent^^.ID := ID1;                        { The event ID }
  1035.     NewUserEvent^^.ID2 := ID2;                        { The optional ID }
  1036.     NewUserEvent^^.Data1 := Data1;                    { The optional data }
  1037.     NewUserEvent^^.Data2 := Data2;                    { The optional data }
  1038.     NewUserEvent^^.theHandle := theHandle;            { The optional handle }
  1039.     NewUserEvent^^.Next := NIL;                    { No next item after this one }
  1040.  
  1041.     if (UserEventList = NIL) then                        { See if anyone is in the list yet }
  1042.         UserEventList := NewUserEvent                { Make this one the first in the list }
  1043.     else
  1044.         begin
  1045.         theUserEvent := UserEventList;                { Get the first one }
  1046.         while (theUserEvent^^.Next <> nil) do        { Get the next one }
  1047.             begin
  1048.             theUserEvent := theUserEvent^^.Next;
  1049.             end;
  1050.         theUserEvent^^.Next := NewUserEvent;        { Tack on to the end }
  1051.         end;
  1052.     end;
  1053. end;
  1054.  
  1055. { ======================================================= }
  1056.  
  1057. { Routine: SetNameForPopup }
  1058. { Purpose: Set the title for a popup control }
  1059.  
  1060. procedure SetNameForPopup(theControl:ControlHandle);
  1061. var
  1062.     theHandle:Handle;                                    { The resource handle }
  1063.     theType:ResType;                                    { Returned type }
  1064.     theID:integer;                                        { Returned ID }
  1065.     theMenuID:integer;                                    { Menu ID }
  1066.  
  1067.  
  1068. begin 
  1069. theMenuID := GetCtlMax(theControl);                    { Get the menu ID }
  1070. theHandle := Get1Resource('MENU',theMenuID);        { See if the resource is out there }
  1071. if (theHandle <> nil) then                                { See if we got the menu }
  1072.     GetResInfo(theHandle,theID,theType,sTemp)    { Get the title }
  1073. else                                                { Else no menu here }
  1074.     sTemp := '';                                    { Get the title }
  1075. SetCTitle(theControl,sTemp);                        { Set the title }
  1076. end;
  1077.  
  1078. { ======================================================= }
  1079.  
  1080. { Routine: Add_List_String }
  1081. { Purpose: This is a routine used to add strings to an existing list }
  1082.  
  1083. procedure Add_List_String(theString:Str255;theList:ListHandle;var cSize:Point) ;
  1084. var
  1085.     theRow:integer;                                        { The Row that we are adding }
  1086.  
  1087.  
  1088. begin
  1089. if (theList <> NIL) then
  1090.     begin
  1091.     cSize.h := 0;                                    { Point to the correct column }
  1092.     theRow := LAddRow(1, 32000, theList);            { Add another row at the end of the list }
  1093.     cSize.v := theRow;                                { Point to the row just added }
  1094.     LSetCell(Pointer(Ord4(@theString) + 1), length(theString),cSize,theList);{ Place string in row just created }
  1095.     end;
  1096. end;
  1097.  
  1098. { ======================================================= }
  1099.  
  1100. { Routine: Make_A_List }
  1101. { Purpose: This is a routine used to make a new list }
  1102.  
  1103. procedure Make_A_List(var theList:ListHandle;var theListRect:Rect;theWindow:WindowPtr;theStringResourceID:integer;
  1104.     theSize,theFont:integer;theStyle:Style;InDialog:Boolean);
  1105. var
  1106.     cSize:Point;                                        { Use to point to proper row }
  1107.     theHandle:Handle;                                    { Temp Handle }
  1108.     dataBounds:Rect;
  1109.  
  1110.  
  1111. begin
  1112. TextSize(theSize);                                    { Set text size }
  1113. TextFont(theFont);                                    { Set text font }
  1114. TextFace(theStyle);                                    { Set text style }
  1115.  
  1116. tempRect := theListRect;
  1117. tempRect.right := tempRect.right - 15;                { Go inside the scroll bar area }
  1118. SetRect(dataBounds, 0, 0, 1, 0);                    { Make the empty list }
  1119. cSize.h := theListRect.right - 15 - theListRect.left;{ Get the width of the list }
  1120. cSize.v := 0;                                        { Set the HEIGHT of each list element, based on font selected }
  1121.  
  1122. theList := LNew(tempRect,dataBounds,cSize,0,theWindow,TRUE, FALSE, FALSE, TRUE);{ Create the list }
  1123. theList^^.selFlags := lOnlyOne + lNoNilHilite;    { Set for only one active item at a time }
  1124. LDoDraw(FALSE,theList);                            { Do not Draw this list structure }
  1125.  
  1126. theHandle := Get1Resource('STR#',theStringResourceID);{ See if any strings }
  1127. if (theHandle <> NIL) then
  1128.     begin
  1129.     cSize.h := 0;                                    { Point to the correct column, starts at zero }
  1130.     cSize.v := -1;                                    { Point to the correct row, starts at zero }
  1131.     repeat
  1132.         GetIndString(sTemp, theStringResourceID, cSize.v + 2);{ Get the new string }
  1133.         if (length(sTemp) > 0) then
  1134.             Add_List_String(sTemp,theList,cSize);{ Add in the new string }
  1135.     until (length(sTemp) = 0);                {Add all the strings in this resource}
  1136.     end;
  1137.  
  1138. LDoDraw(TRUE,theList);                                { Draw this list structure }
  1139. cSize.h := 0;                                        { All elements are in column 0e }
  1140. cSize.v := 0;                                         { Select the first list element }
  1141. LSetSelect(TRUE, cSize,theList);
  1142.  
  1143. if (InDialog) then
  1144.     TextFont(systemFont)                            { Back to the system font }
  1145. else
  1146.     TextFont(applFont);                                { Back to the application font }
  1147. TextSize(12);                                        { Back to the application size }
  1148. TextFace([]);                                        { Set text style }
  1149. end;
  1150.  
  1151. { ======================================================= }
  1152.  
  1153. procedure Play_The_Sound(ResID:integer);
  1154. var
  1155.     ResHandle:Handle;                                { The sound resource handle }
  1156.     SndResourceID:integer;                            { Sound resource ID }
  1157.     SndName:Str255;                                { Sound name}
  1158.     theType:ResType;                                { Resource type }
  1159.     MyErr:OSErr;                                    { Error flag }
  1160.  
  1161.  
  1162. begin
  1163. ResHandle := Get1Resource('snd ', ResID);            { See if the resource is out there }
  1164. if (ResHandle <> NIL) then                                { Only do if we got the sound }
  1165.     begin
  1166.     GetResInfo(ResHandle,SndResourceID,theType,SndName);
  1167.     MyErr := SndPlay(NIL,ResHandle,FALSE);
  1168.     ReleaseResource(ResHandle);
  1169.     end;
  1170. end;
  1171.  
  1172. { ======================================================= }
  1173.  
  1174. { Routine: Get_TE_String }
  1175. { Purpose: This is a routine used to get a string from a TE area, limited to 250 characters }
  1176.  
  1177.  procedure Get_TE_String (theTEArea: TEHandle; var theString: Str255);
  1178.   var
  1179.    Index: integer;                                        { Use to loop thru the characters }
  1180.    TitleLength: integer;                                    { Number of characters to do }
  1181.    theCharsHandle: CharsHandle;                            { Used to get global edit text }
  1182.    theStringPtr: Ptr;                                    { Pointer to the string, byte level }
  1183.  
  1184.  
  1185.  begin
  1186.   theCharsHandle := TEGetText(theTEArea);                { Get the character handle }
  1187.   HLock(Handle(theCharsHandle));                        { Lock it for safety }
  1188.   TitleLength := theTEArea^^.teLength;                { Get the number of characters }
  1189.   theString := '';                                    { Start with an empty string }
  1190.   if (TitleLength > 0) then
  1191.    begin
  1192.     if (TitleLength > 250) then
  1193.      TitleLength := 250;
  1194.     for Index := 1 to TitleLength do
  1195.      theString := concat(theString, theCharsHandle^^[Index - 1]);
  1196.    end;                                {End of IF}
  1197.  end;
  1198.  
  1199. { ======================================================= }
  1200.  
  1201. { Routine: Make_TE_Area }
  1202. { Purpose: This is a routine used to create a TE area }
  1203.  
  1204. procedure Make_TE_Area(var theTEArea:TEHandle;var Position:Rect;theFontSize,theFont,DefaultStringID:integer);
  1205. var
  1206.     ThisFontInfo:FontInfo;                            { Use to get the font data }
  1207.  
  1208.  
  1209. begin
  1210. TextSize(theFontSize);                                { Set the size }
  1211. TextFont(theFont);                                    { Set the font }
  1212. GetFontInfo(ThisFontInfo);                            { Get Ascent height for positioning }
  1213.  
  1214. tempRect := Position;                                { Get the rect }
  1215. FrameRect(tempRect);                                { Frame this TE area }
  1216. InsetRect(tempRect, 3, 3);                            { Indent for TE inside of box }
  1217. theTEArea := TENew(tempRect,tempRect);            { Create the TE area }
  1218. if (theInput <> NIL) then                                { See if there is already a TE area }
  1219.     TEDeactivate(theInput);                            { Yes, so turn it off }
  1220.  
  1221. theInput := theTEArea;                                { Activate the TE area }
  1222. GetIndString(sTemp,DefaultStringID,1);            { Get the default string }
  1223. TESetText(Pointer(Ord4(@sTemp) + 1), length(sTemp), theTEArea);{Place default text in the TE area}
  1224. TEActivate(theInput);                                { Make the TE area active }
  1225.  
  1226. TextSize(12);                                        { Restore the size }
  1227. TextFont(applFont);                                    { Restore the font }
  1228. end;
  1229.  
  1230. { ======================================================= }
  1231.  
  1232. { Routine: Plot_Sicn }
  1233. { Purpose: This is a routine used to plot an Sicn, small 16x16 icon }
  1234.  
  1235. procedure Plot_Sicn(theSicnID:integer;Position:Rect);
  1236. type
  1237.    SmallIconRec = record
  1238.      theIcon: array[0..15] of LongInt;
  1239.     end;
  1240.    SmallIconPtr = ^SmallIconRec;
  1241.    SmallIconHand = ^SmallIconPtr;
  1242. var
  1243.     SmallIcon:SmallIconHand;                            { Handle to the SICN resource }
  1244.     theBitMap:BitMap;                            { Bitmap for plotting }
  1245.     sourceRect, DestRect:Rect;                { Rects for plotting }
  1246.     thePort:GrafPtr;                            { Port to draw on to }
  1247.  
  1248.  
  1249. begin 
  1250. SmallIcon := SmallIconHand(GetResource('SICN',theSicnID));{ Get the resource }
  1251. if (SmallIcon <> NIL) then                                { Do if there is a resource }
  1252.     begin
  1253.     SetRect(sourceRect, 0, 0, 16, 16);                { Sicns are 16 x 16 }
  1254.     DestRect := Position;                            { Destination }
  1255.     with theBitMap do                        {Fill in the bitmap}
  1256.      begin
  1257.       baseAddr := @SmallIcon^^.theIcon;        {Base address of the bitmap}
  1258.       rowBytes := 2;                        {2*8 = 16}
  1259.       bounds := sourceRect;                    {Source rect size}
  1260.      end;
  1261.     GetPort(thePort);                                { Get the current port }
  1262.     CopyBits(theBitMap,thePort^.portBits,sourceRect,DestRect, srcCopy, NIL);{ Plot it }
  1263.     end;
  1264. end;
  1265.  
  1266. { ======================================================= }
  1267.  
  1268. { Routine: HandleWScrollBar }
  1269. { Purpose: This is a routine used to handle a scrollbar }
  1270.  
  1271. procedure HandleWScrollBar(myPt:Point;code,Increment,LIncrement:integer;theControl:ControlHandle);
  1272. var
  1273.     theValue:integer;                                    { Value of the scrollbar }
  1274.     MaxTick:longint;                                    { Timer used for repeat scrolling }
  1275.     FirstTime:Boolean;                                    { Flag to start scrolling }
  1276.     Start,Stop:integer;
  1277.  
  1278.  
  1279. begin
  1280. Start := GetCtlMin(theControl);
  1281. Stop := GetCtlMax(theControl);
  1282.  
  1283. FirstTime := TRUE;                                    { Do the scroll the first time also }
  1284. while (StillDown or FirstTime)    do                { Do the scroll as long as the button is down }
  1285.    begin
  1286.     FirstTime := FALSE;                                { Do the scroll the first time only unless auto }
  1287.     HiliteControl(theControl, code);                { Darken the arrow }
  1288.     theValue := GetCtlValue(theControl);                { Get current state }
  1289.  
  1290.     if (code = inUpButton) then                        { See if in the up/left arrow }
  1291.         begin
  1292.         theValue := theValue - Increment;            { Subtract the single decrement }
  1293.         if (theValue < Start) then                        { Check for boundary conditions }
  1294.             theValue := Start;                        { Bump at the start value }
  1295.         end
  1296.     else if (code = inDownButton) then                        { See if in the down/right arrow }
  1297.         begin
  1298.         theValue := theValue + Increment;            { Add the single increment }
  1299.         if (theValue > Stop) then                         { Check for boundary conditions }
  1300.             theValue := Stop;                        { Bump at the stop value }
  1301.         end
  1302.     else if (code = inPageUp) then                            { See if in the up/left grey area }
  1303.         begin
  1304.         theValue := theValue - LIncrement;            { Subtract the page increment }
  1305.         if (theValue < Start) then                         { Check for boundary conditions }
  1306.             theValue := Start;                        { Bump at the Start value }
  1307.         end
  1308.     else if (code = inPageDown)    then                        { See if in the down/right grey area }
  1309.         begin
  1310.         theValue := theValue + LIncrement;            { Add the page increment }
  1311.         if (theValue > Stop) then                        { Check for boundary conditions }
  1312.             theValue := Stop;                        { Bump at the Stop value }
  1313.         end
  1314.     else if (code = inThumb) then                            { See if in the drag box area }
  1315.         begin
  1316.         code := TrackControl(theControl,myPt,NIL);    { Let the OS drag it around }
  1317.         theValue := GetCtlValue(theControl);            { Get current state }
  1318.         end;
  1319.  
  1320.     SetCtlValue(theControl, theValue);                { Set new state }
  1321.  
  1322.     MaxTick := TickCount + 9;                        { Time delay for auto-scroll }
  1323.     repeat                                                { Start of delay routine }
  1324.     until (not (Button) or (TickCount > MaxTick));    { Exit when time up or mouse button up }
  1325.     HiliteControl(theControl, 0);                    { Lighten the arrow }
  1326.     end;                                                { End for StillDown }
  1327. end;
  1328.  
  1329. { ======================================================= }
  1330.  
  1331. { Routine: mySelectDlgFilter }
  1332. { Purpose: Filter routine for Select Volume routine }
  1333.  
  1334. function mySelectDlgFilter(item:integer;theDialog:DialogPtr;myDataPtr:Ptr):integer;
  1335. var
  1336.     theItem,theWidth,theNameWidth,DType:integer;
  1337.     DItem:Handle;
  1338.     CItem:ControlHandle;
  1339.     sTemp,theName,LastChar:Str255;
  1340.     cSize:Point;
  1341.     dataBounds:Rect;
  1342.     NamesAreSame:Boolean;
  1343.  
  1344.  
  1345. begin
  1346. theItem := item;
  1347.  
  1348. if (theItem = sfHookNullEvent) then
  1349.     begin
  1350.     if ((Last_vRefNum <> Files.theStdFileReply.sfFile.vRefNum) or (Last_parID <> Files.theStdFileReply.sfFile.parID) or (Last_Name <> Files.theStdFileReply.sfFile.name)) then
  1351.      theItem := sfItemFileListUser;
  1352.     end
  1353. else
  1354.     theItem := theItem;
  1355.  
  1356. if (theItem = sfItemFileListUser) then
  1357.     begin
  1358.     if ((Last_vRefNum <> Files.theStdFileReply.sfFile.vRefNum) or (Last_parID <> Files.theStdFileReply.sfFile.parID) or (Last_Name <> Files.theStdFileReply.sfFile.name)) then
  1359.         begin
  1360.         Last_vRefNum := Files.theStdFileReply.sfFile.vRefNum;
  1361.         Last_parID := Files.theStdFileReply.sfFile.parID;
  1362.         Last_Name := Files.theStdFileReply.sfFile.name;
  1363.         GetDItem(theDialog,10,DType,DItem,tempRect);
  1364.         theWidth := tempRect.right - tempRect.left - 10;
  1365.         sTemp := 'Select "';
  1366.         theWidth := theWidth - StringWidth(sTemp);
  1367.         theName := Files.theStdFileReply.sfFile.name;
  1368.         theNameWidth := StringWidth(theName);
  1369.         if (theNameWidth > theWidth) then
  1370.             begin
  1371.             LastChar := copy(theName, length(theName), 1);
  1372.             sTemp := concat(theName, '...', LastChar);
  1373.             while (StringWidth(sTemp) > (theWidth - 5)) do
  1374.                 begin
  1375.                 sTemp := copy(theName, 1, length(theName) - 1);
  1376.                 theName := sTemp;
  1377.                    sTemp := concat(theName, '...', LastChar);
  1378.                    end;
  1379.                theName := concat(theName, '...', LastChar);
  1380.                end;
  1381.         sTemp := concat('Select "', theName, '"');
  1382.         CItem := ControlHandle(DItem);                { Change dialog handle to control handle }
  1383.         SetCTitle(CItem,sTemp);
  1384.         if (Files.theStdFileReply.sfIsFolder or Files.theStdFileReply.sfIsVolume) then
  1385.             HiliteControl(CItem, 0)
  1386.         else
  1387.             HiliteControl(CItem,255);
  1388.         end;
  1389.     end
  1390. else if (theItem = 10) then
  1391.     theItem := sfItemOpenButton;
  1392.  
  1393.   mySelectDlgFilter := theItem;
  1394. end;
  1395.  
  1396. { ======================================================= }
  1397.  
  1398. { Routine: mySelectCustomFileFilter }
  1399. { Purpose: Filter file routine for Select Volume routine }
  1400.  
  1401.  function mySelectCustomFileFilter (pb: CInfoPBPtr; myDataPtr: Ptr): Boolean;
  1402.   var
  1403.    HideTheItem: Boolean;
  1404.  
  1405.  
  1406.  begin
  1407.   HideTheItem := true;
  1408.   if (BAND(pb^.ioFlAttrib, $0010) <> 0) then    {Doing Folder}
  1409.    HideTheItem := false;
  1410.   mySelectCustomFileFilter := HideTheItem;
  1411.  end;
  1412.  
  1413. { ======================================================= }
  1414.  
  1415. { Routine: Do_The_Select_Volume }
  1416. { Purpose: This is a routine used to select a user selected folder or volume }
  1417. { Return TRUE for opened the file OK, else return FALSE }
  1418.  
  1419. function Do_The_Select_Volume(var theFile:FSSpec):Boolean;        { Select a volume }
  1420. var
  1421.     Screen_Width:integer;                                { Size of the current screen }
  1422.     Screen_Height:integer;                                { Size of the current screen }
  1423.     Where:Point;                                        { Used for placing the SF dialog }
  1424.     OpenedOK:Boolean;                                    { Flag to return }
  1425.  
  1426.  
  1427. begin
  1428. Screen_Width := screenBits.bounds.right - screenBits.bounds.left;{ Width of this screen }
  1429. Screen_Height := screenBits.bounds.bottom - screenBits.bounds.top;
  1430.  
  1431. Where.h := (Screen_Width div 2) - (304 div 2);            { Place to put this dialog }
  1432. Where.v := (Screen_Height div 4) - (104 div 2);
  1433. if (Where.v < 60) then
  1434.     Where.v := 60;
  1435. InitCursor;
  1436. Files.typeList[0] := 'GRC ';
  1437. Last_vRefNum := -2;
  1438. Last_parID := -2;
  1439. CustomGetFile(@mySelectCustomFileFilter, 0, Files.typeList, Files.theStdFileReply, 512, Where, @mySelectDlgFilter, nil, nil, nil, nil);
  1440.  
  1441. OpenedOK := false;                                    { Init to did not open the file }
  1442. if (Files.theStdFileReply.sfGood) then                    { Only do if the user did not cancel }
  1443.     begin
  1444.     theFile := Files.theStdFileReply.sfFile;        { Save the FSSpec }
  1445.     Files.inputFileName := Files.theStdFileReply.sfFile.name;
  1446.     OpenedOK := true;                                { We selected a folder }
  1447.     end
  1448. else
  1449.     Files.inputFileName := '';                        { No name for a folder }
  1450.  
  1451. Do_The_Select_Volume := OpenedOK;
  1452. end;
  1453.  
  1454. { ======================================================= }
  1455.  
  1456. { Routine: Do_The_Open_File }
  1457. { Purpose: This is a routine used to open a user selected file }
  1458. { Return TRUE for opened the file OK, else return FALSE }
  1459.  
  1460. function Do_The_Open_File(NumberOfTypes:integer;var theVolRefNum:integer;fileFilter,dlgHook:ProcPtr):Boolean;
  1461. var
  1462.     Screen_Width:integer;                                { Size of the current screen }
  1463.     Screen_Height:integer;                                { Size of the current screen }
  1464.     Where:Point;                                        { Used for placing the SF dialog }
  1465.     OpenedOK:Boolean;                                    { Flag to return }
  1466.     ErrorCode:OSErr;
  1467.  
  1468.  
  1469. begin
  1470. Screen_Width := screenBits.bounds.right - screenBits.bounds.left;{ Width of this screen }
  1471. Screen_Height := screenBits.bounds.bottom - screenBits.bounds.top;
  1472.  
  1473. Where.h := (Screen_Width div 2) - (304 div 2);            { Place to put this dialog }
  1474. Where.v := (Screen_Height div 4) - (104 div 2);
  1475. if (Where.v < 60) then
  1476.     Where.v := 60;
  1477. InitCursor;
  1478. SFGetFile(Where, ' not used ', fileFilter, NumberOfTypes, Files.typeList, dlgHook, Files.Reply);
  1479.  
  1480. theVolRefNum := 0;
  1481. Files.inputRefNum := 0;                                { We did not open }
  1482.  
  1483. OpenedOK := false;                                    { Init to did not open the file }
  1484. if (Files.Reply.good) then                                { Only do if the user did not cancel }
  1485.     begin
  1486.     Files.inputFileName := Files.Reply.fName;
  1487.     ErrorCode := SetVol(nil, Files.Reply.vRefNum);    { Set to this volume for later opens }
  1488.     theVolRefNum := Files.Reply.vRefNum;
  1489.     OpenedOK := true;                                { Flag that we are open OK }
  1490.     end
  1491. else
  1492.     Files.inputFileName := '';                        { No name for a file }
  1493.  
  1494. Do_The_Open_File := OpenedOK;
  1495. end;
  1496.  
  1497. { ======================================================= }
  1498.  
  1499. { Routine: Do_The_Save_File }
  1500. { Purpose: This is a routine used to save a user selected file }
  1501. { Return TRUE for opened the file OK, else return FALSE }
  1502.  
  1503. function Do_The_Save_File(creator,fileType:OSType;Prompt,DefaultName:Str255;
  1504.     var theVolRefNum,theRefNum:integer;dlgHook:ProcPtr):Boolean;
  1505. var
  1506.     Screen_Width:integer;                                { Size of the current screen }
  1507.     Screen_Height:integer;                                { Size of the current screen }
  1508.     Where:Point;                                        { Used for placing the SF dialog }
  1509.     OpenedOK:Boolean;                                    { Flag to return }
  1510.     ErrorCode:OSErr;
  1511.  
  1512.  
  1513. begin
  1514. Screen_Width := screenBits.bounds.right - screenBits.bounds.left;{ Width of this screen }
  1515. Screen_Height := screenBits.bounds.bottom - screenBits.bounds.top;
  1516.  
  1517. Where.h := (Screen_Width div 2) - (304 div 2);            { Place to put this dialog }
  1518. Where.v := (Screen_Height div 4) - (104 div 2);
  1519. if (Where.v < 60) then
  1520.     Where.v := 60;
  1521. InitCursor;
  1522. SFPutFile(Where,Prompt,DefaultName,dlgHook,Files.Reply);
  1523.  
  1524. Files.outputFileName := Files.Reply.fName;
  1525. theVolRefNum := Files.Reply.vRefNum;
  1526. theRefNum := 0;
  1527. Files.outputRefNum := 0;
  1528.  
  1529. OpenedOK := false;                                    { Init to did not open the file }
  1530. if (Files.Reply.good) then                                { Only do if the user did not cancel }
  1531.     begin
  1532.     ErrorCode := FSDelete(Files.Reply.fName,Files.Reply.vRefNum);{ Delete an older file }
  1533.     ErrorCode := Create(Files.Reply.fName,Files.Reply.vRefNum,creator,fileType);{ Create the file }
  1534.     ErrorCode := FSOpen(Files.Reply.fName,Files.Reply.vRefNum,Files.outputRefNum);{ Try to open the file }
  1535.  
  1536.     if (ErrorCode = 0) then                                { See if we opened it cleanly }
  1537.         begin
  1538.         ErrorCode := SetFPos(Files.outputRefNum,fsFromStart,0);{ Start at file beginning }
  1539.         ErrorCode := SetVol(nil,theVolRefNum);        { Set for later saves }
  1540.         theRefNum := Files.outputRefNum;
  1541.         theVolRefNum := Files.Reply.vRefNum;
  1542.         OpenedOK := true;                            { We opened the file OK }
  1543.         end
  1544.     else
  1545.         begin
  1546.         ErrorCode := FSClose(Files.outputRefNum);    { Close it if we can, safety }
  1547.         SysBeep(20);                                { Just beep at the user, caller can do more }
  1548.         Files.outputRefNum := 0;                        { Make sure the refnum is inited }
  1549.         end;
  1550.     end;
  1551.  
  1552. Do_The_Save_File := OpenedOK;
  1553. end;
  1554.  
  1555. { ======================================================= }
  1556.  
  1557. { Routine: PageSetup }
  1558. { Purpose: Do the page setup }
  1559.  
  1560. procedure PageSetup;
  1561. var
  1562.     Result:Boolean;                                        { Result from Setup dialog }
  1563.  
  1564.  
  1565. begin
  1566. PrOpen;                                            { Open the printer driver }
  1567.  
  1568. if (PrError = noErr) then                                { Only do if no error  }
  1569.     begin
  1570.     if (Printing.hPrint = NIL) then                    { Make a print record if there is none }
  1571.         begin
  1572.         Printing.hPrint := THPrint(NewHandle(sizeof(TPrint)));
  1573.         HLock(Handle(Printing.hPrint));
  1574.         PrintDefault(Printing.hPrint);                { Init to default values }
  1575.         end;
  1576.  
  1577.     Result := PrStlDialog(Printing.hPrint);            { Setup dialog }
  1578.     PrClose;
  1579.     end
  1580. else
  1581.     SysBeep(1);
  1582. end;
  1583.  
  1584. { ======================================================= }
  1585.  
  1586. { Routine: PrintJobSetup }
  1587. { Purpose: Do the job setup }
  1588.  
  1589. procedure PrintJobSetup;
  1590. var
  1591.     Result:Boolean;                                        { Result from Setup dialog }
  1592.  
  1593.  
  1594. begin
  1595. PrOpen;                                            { Open the printer driver }
  1596.  
  1597. if (PrError = noErr) then                                { Only do if no error  }
  1598.     begin
  1599.     if (Printing.hPrint = NIL) then                        { Make a print record if there is none }
  1600.         begin
  1601.         Printing.hPrint := THPrint(NewHandle(sizeof(TPrint)));
  1602.         HLock(Handle(Printing.hPrint));
  1603.         PrintDefault(Printing.hPrint);                { Init to default values }
  1604.         end;
  1605.  
  1606.     Result := PrJobDialog(Printing.hPrint);            { Setup dialog }
  1607.     PrClose;
  1608.     end
  1609. else
  1610.     SysBeep(1);
  1611. end;
  1612.  
  1613. { ======================================================== }
  1614.  
  1615. { Routine: OpenThePrinter }
  1616. { Purpose: Open the printer and driver for use }
  1617.  
  1618. procedure OpenThePrinter(var Cancelled:Boolean);
  1619.  
  1620.  
  1621. begin
  1622. PrOpen;                                            { Open the printer driver }
  1623.  
  1624. if (PrError = noErr) then                                { Only do if no error }
  1625.     begin
  1626.     Printing.PrinterIsOpen := FALSE;                    { Whether printer is open or not }
  1627.     if (Printing.hPrint = NIL) then                        { Make a print record if there is none }
  1628.         begin
  1629.         Printing.hPrint := THPrint(NewHandle(sizeof(TPrint)));
  1630.         HLock(Handle(Printing.hPrint));
  1631.         PrintDefault(Printing.hPrint);                { Init to default values }
  1632.         end;
  1633.  
  1634.     Cancelled := PrJobDialog(Printing.hPrint);        { Setup dialog }
  1635.     Printing.CopyCount := Printing.hPrint^^.prJob.iCopies;    { Get number of copies to do }
  1636.     Cancelled := not(Cancelled);                        { Inverted logic }
  1637.  
  1638.     Printing.pPrPort := nil;
  1639.  
  1640.     if (not(Cancelled)) then                        { Do if they did not cancel }
  1641.         begin
  1642.         Printing.PrinterIsOpen := true;                { Whether printer is open or not }
  1643.         Printing.PageCount := 1;                        { For adding in page number }
  1644.         Printing.LineCount := 1;                        { For printing }
  1645.         Printing.pPrPort := PrOpenDoc(Printing.hPrint, nil, nil);{ Get printing port }
  1646.         end;
  1647.     end
  1648. else
  1649.     begin
  1650.     SysBeep(1);
  1651.     Cancelled := TRUE;
  1652.     end;
  1653. end;
  1654.  
  1655. { ======================================================= }
  1656.  
  1657. { Routine: CloseThePrinter }
  1658. { Purpose: Close the printer }
  1659.  
  1660. procedure CloseThePrinter;
  1661.  
  1662.  
  1663. begin
  1664. if (Printing.pPrPort <> nil) then                        { Do if we have a port }
  1665.     begin
  1666.     PrCloseDoc(Printing.pPrPort);                    { Clear printing port }
  1667.     Printing.pPrPort := nil;
  1668.     end;
  1669.  
  1670. if (Printing.hPrint <> nil)     then                        { Do if we have a record }
  1671.     begin
  1672.     if ((Printing.hPrint^^.prJob.bJDocLoop = bSpoolLoop) and (PrError = noErr)) then
  1673.         PrPicFile(Printing.hPrint, NIL, NIL, NIL,Printing.prStatus);{ Spool it }
  1674.     end;
  1675. end;
  1676.  
  1677. { ======================================================= }
  1678.  
  1679. { Routine: SetupTheItem }
  1680. { Purpose: Setup a dialog or alert item }
  1681.  
  1682. procedure SetupTheItem(theDialog:DialogPtr;ItemID:integer;SizeIt,ShowIt,EnableIt,SetTheMax:Boolean;
  1683.     thePosition:Rect;ExtraData:longint;StringID:integer);
  1684. var
  1685.     tempRect:Rect;                                { Temporary rectangle }
  1686.     DType:integer;                                { Type of dialog item }
  1687.     DItem:Handle;                                { Handle to the dialog item }
  1688.     CItem:ControlHandle;                        { Control handle }
  1689.  
  1690.  
  1691. begin
  1692. GetDItem(theDialog,ItemID,DType,DItem,tempRect);    { Get the item handle and size }
  1693. CItem := ControlHandle(DItem);                        { Change to control handle }
  1694.  
  1695. if (SizeIt)    then                                        { Have to resize all CDEF connected controls }
  1696.     SizeControl(CItem, tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);{ Size it }
  1697. thePosition := tempRect;                            { Pass back the zone location and size }
  1698.  
  1699. if (ExtraData <> 0) then                                { See if extra data for a CDEF }
  1700.     CItem^^.contrlData := Handle(ExtraData);        { Send it }
  1701.  
  1702. if (StringID <> 0) then                                { See if a CDEF and needs the title set again}
  1703.     begin
  1704.     GetIndString(sTemp,StringID,1);                    { Get the string }
  1705.     SetCTitle(CItem,sTemp);                            { Set the string }
  1706.     end;
  1707.  
  1708. if (EnableIt) then                                        { See if enable or disable the zone }
  1709.     HiliteControl (CItem,0)                        { Enable the zone }
  1710. else
  1711.     HiliteControl (CItem,255);                        { Dim the zone }
  1712.  
  1713. if (SetTheMax) then
  1714.     SetCtlMax(CItem,12345);                            { Set the flag to the CDEF }
  1715.  
  1716. if (ShowIt) then
  1717.     ShowControl(CItem);                                { Show it to activate it }
  1718. end;
  1719.  
  1720. { ======================================================= }
  1721.  
  1722. { Routine: CenterOnColorScreen }
  1723. { Purpose: Center a window onto the deepest color screen }
  1724.  
  1725. procedure CenterOnColorScreen(theWindow:WindowPtr);
  1726. var
  1727.     tempRect,gdRect,temp2Rect:Rect;                    { Temporary rectangle }
  1728.     theDevice:GDHandle;                                { Graphic device }
  1729.  
  1730.  
  1731. begin
  1732. if ((theWindow <> NIL) and (Has.ColorQD)) then            { Make sure it is safe to go ahead }
  1733.     begin
  1734.     SetRect(tempRect,-32000,-32000,32000,32000);    { Look in all directions }
  1735.     theDevice := GetMaxDevice(tempRect);            { Get the deepest device }
  1736.  
  1737.     if (theDevice <> NIL) then                            { Make sure we got a device }
  1738.         begin
  1739.         gdRect := theDevice^^.gdRect;                { Get the device rect }
  1740.         temp2Rect := theWindow^.portRect;            { Get the window rect }
  1741.  
  1742.         tempRect.top := gdRect.top + ((gdRect.bottom-gdRect.top) div 2) - ((temp2Rect.bottom-temp2Rect.top) div 2);
  1743.         tempRect.left := gdRect.left + ((gdRect.right-gdRect.left) div 2) - ((temp2Rect.right-temp2Rect.left) div 2);
  1744.         MoveWindow(theWindow, tempRect.left, tempRect.top,TRUE);{ Move the window}
  1745.         SetPort(theWindow);                         { Prepare to write into our window }
  1746.         end;
  1747.     end;
  1748. end;
  1749.  
  1750. { ======================================================= }
  1751.  
  1752. { Routine: GetDeepestColorScreenRect }
  1753. { Purpose: Get the deepest color screen rect }
  1754.  
  1755. procedure GetDeepestColorScreenRect(DeepRect:Rect);
  1756. var
  1757.     tempRect:Rect;                                    { Temporary rectangle }
  1758.     theDevice:GDHandle;                                { Graphic device }
  1759.  
  1760.  
  1761. begin
  1762. DeepRect := screenBits.bounds;                        { Default to the main screen }
  1763. theDevice := NIL;                                    { Default to no device }
  1764. if (Has.ColorQD) then                                    { See if color QuickDraw is around }
  1765.     begin
  1766.     SetRect(tempRect,-32000,-32000,32000,32000);    { Look in all directions }
  1767.     theDevice := GetMaxDevice(tempRect);            { Get the deepest device }
  1768.  
  1769.     if (theDevice <> NIL) then                        { Make sure we got a device }
  1770.         DeepRect := theDevice^^.gdRect;                { Get the device rect }
  1771.     end;
  1772. end;
  1773.  
  1774. { ======================================================= }
  1775.  
  1776. procedure HiliteDefaultButton(theDialog:DialogPtr;theItem:integer);
  1777. var
  1778.     tempRect:Rect;
  1779.     DType:integer;                                { Type of dialog item }
  1780.     DItem:Handle;                                { Handle to the dialog item }
  1781.  
  1782.  
  1783. begin
  1784. GetDItem(theDialog,theItem,DType,DItem,tempRect);    { Get the item handle }
  1785. PenSize(3, 3);                                        { Change pen to draw thick default outline }
  1786. InsetRect(tempRect, -4, -4);                        { Draw outside the button by 1 pixel }
  1787. FrameRoundRect(tempRect,16,16);                        { Draw the outline }
  1788. PenSize(1, 1);                                         { Restore the pen size to the default value }
  1789. end;
  1790.  
  1791. { ======================================================= }
  1792.  
  1793. procedure CheckKeysInDialog(theDialog:DialogPtr;var valMyFilter:Boolean;var theEvent:EventRecord;var itemHit:integer);
  1794. var
  1795.     chCode:integer;                                { Key entered }
  1796.     MyCmdKey:char;                                { The command key }
  1797.     CmdDown:Boolean;                            { Flag for command key used }
  1798.     tempRect:Rect;                                { Temporary rectangle }
  1799.     DType:integer;                                { Type of dialog item }
  1800.     DItem:Handle;                                { Handle to the dialog item }
  1801.     CItem:ControlHandle;                        { Control handle }
  1802.     LTemp:longint;
  1803.  
  1804.  
  1805. begin
  1806. if (theEvent.what = keyDown) then
  1807.     begin
  1808.     chCode := BAND(theEvent.message,charCodeMask);{ Get character }
  1809.     MyCmdKey := char(chCode);                        { Change to ASCII }
  1810.     CmdDown := (BAND(theEvent.modifiers,cmdKey) <> 0);{ Get command key state }
  1811.     if (CmdDown) then                                    { Do if command key was down }
  1812.         begin
  1813.         if ((MyCmdKey = 'x') or (MyCmdKey = 'X')) then
  1814.             begin
  1815.             DlgCut(theDialog);
  1816.             valMyFilter := TRUE;
  1817.             end
  1818.         else if ((MyCmdKey ='c') or (MyCmdKey = 'C')) then
  1819.             begin
  1820.             DlgCopy(theDialog);
  1821.             valMyFilter := TRUE;
  1822.             end
  1823.         else if ((MyCmdKey ='v') or (MyCmdKey = 'V')) then
  1824.             begin
  1825.             DlgPaste(theDialog);
  1826.             valMyFilter := TRUE;
  1827.             end;
  1828.         end
  1829.     else if ((chCode = 13) or (chCode = 3)) then        { CR or Enter }
  1830.         begin
  1831.         valMyFilter := TRUE;                            { Flag we got a hit }
  1832.         itemHit := 1;                                { Default for CR }
  1833.         GetDItem(theDialog,itemHit,DType,DItem,tempRect);{ Get the item }
  1834.         if (DType = (ctrlItem + btnCtrl)) then            { If a button then ... }
  1835.             begin
  1836.             CItem := ControlHandle(DItem);            { Make it a controlhandle }
  1837.             HiliteControl(CItem,10);                { Hilite it }
  1838.             LTemp := TickCount + 15;                { Flash the button for 1/4 second }
  1839.               repeat
  1840.             until (LTemp < TickCount);
  1841.             HiliteControl(CItem, 0);                { UnHilite it }
  1842.             end;
  1843.         end;
  1844.     end;
  1845. end;
  1846.  
  1847. { ======================================================= }
  1848.  
  1849. procedure SetupNormalControl(theDialog:DialogPtr;theItem:integer;Enabled:Boolean;InitialValue:integer);
  1850. var
  1851.     tempRect:Rect;                                    { Temporary rectangle variable }
  1852.     DType:integer;                                    { Type of dialog item }
  1853.     DItem:Handle;                                    { Handle to the dialog item }
  1854.     CItem:ControlHandle;                            { Control handle }
  1855.  
  1856.  
  1857. begin
  1858. GetDItem(theDialog,theItem,DType,DItem,tempRect);    { Get the item handle }
  1859. CItem := ControlHandle(DItem);                        { Change dialog handle to control handle }
  1860.  
  1861. if (Enabled) then                                        { See if enable or disable the zone }
  1862.     HiliteControl (CItem,0)                        { Enable the zone }
  1863. else
  1864.     HiliteControl (CItem,255);                        { Dim the zone }
  1865.  
  1866. SetCtlValue(CItem,InitialValue);
  1867. end;
  1868.  
  1869. { ======================================================= }
  1870.  
  1871. procedure BasicSetup(theDialog:DialogPtr;theItem:integer;Enabled:Boolean;MessageResID:integer;
  1872.     var theCItem:ControlHandle);
  1873. var
  1874.     tempRect:Rect;                                { Temporary rectangle variable }
  1875.     DType:integer;                                { Type of dialog item }
  1876.     DItem:Handle;                                { Handle to the dialog item }
  1877.     CItem:ControlHandle;                        { Control handle }
  1878.     sTemp:Str255;
  1879.  
  1880.  
  1881. begin
  1882. GetDItem(theDialog,theItem,DType,DItem,tempRect);{ Get the item handle }
  1883. CItem := ControlHandle(DItem);                        { Change dialog handle to control handle }
  1884. SizeControl(CItem,tempRect.right-tempRect.left, tempRect.bottom-tempRect.top);{ Size it }
  1885.  
  1886. if (Enabled) then                                        { See if enable or disable the zone }
  1887.     HiliteControl (CItem,0)                        { Enable the zone }
  1888. else
  1889.     HiliteControl (CItem,255);                        { Dim the zone }
  1890.  
  1891. SetCtlValue(CItem,0);
  1892.  
  1893. if (MessageResID <> 0) then
  1894.     begin
  1895.     GetIndString(sTemp,MessageResID,1);                { Get the string }
  1896.     SetCTitle(CItem,sTemp);                            { Set the string }
  1897.     end;
  1898. theCItem := CItem;
  1899. end;
  1900.  
  1901. { ======================================================= }
  1902.  
  1903. procedure SetupHotSpot(theDialog:DialogPtr;theItem:integer;MakeHotSpot:Boolean;LineWidth,ShadowWidth:longint;
  1904.     MessageResID:integer;Enabled:Boolean);
  1905. var
  1906.     CItem:ControlHandle;                                { Control handle }
  1907.     LTemp:longint;
  1908.  
  1909.  
  1910. begin
  1911. BasicSetup(theDialog,theItem,Enabled,MessageResID,CItem);
  1912.  
  1913. if (MakeHotSpot) then
  1914.     LTemp := $00FF0000                                { Tell the CDEF that it is a HotSpot }
  1915. else
  1916.     LTemp := $00000000;                                { Tell the CDEF that it is a Rectangle }
  1917.  
  1918. if (MessageResID <> 0) then
  1919.     LTemp := LTemp + $01000000;
  1920.  
  1921. LTemp := LTemp + (BAND($000000FF,LineWidth) * $00000100);    { Set the line width }
  1922. LTemp := LTemp + BAND($000000FF,ShadowWidth);            { Set the shadow width }
  1923.  
  1924. CItem^^.contrlData := Handle(LTemp);                { Send it }
  1925.  
  1926. ShowControl(CItem);                                    { Show it to activate it }
  1927. end;
  1928.  
  1929. { ======================================================= }
  1930.  
  1931. procedure SetupPlugin(theDialog:DialogPtr;theItem:integer;Enabled:Boolean;NormalID,HilitedID:longint;
  1932.     MessageResID:integer);
  1933. var
  1934.     CItem:ControlHandle;                                { Control handle }
  1935.     LTemp:longint;
  1936.  
  1937.  
  1938. begin
  1939. BasicSetup(theDialog,theItem,Enabled,MessageResID,CItem);
  1940.  
  1941. LTemp := (HilitedID * $00010000) + NormalID;    
  1942. CItem^^.contrlData := Handle(LTemp);                { Send it }
  1943.  
  1944. SetCtlMax(CItem,12345);                                { Set the flag to the CDEF }
  1945.  
  1946. ShowControl(CItem);                                    { Show it to activate it }
  1947. end;
  1948.  
  1949. { ======================================================= }
  1950.  
  1951. procedure SetupMinMaxValue(theDialog:DialogPtr;theItem,min,max,value:integer);
  1952. var
  1953.     tempRect:Rect;                                { Temporary rectangle variable }
  1954.     DType:integer;                                { Type of dialog item }
  1955.     DItem:Handle;                                { Handle to the dialog item }
  1956.     CItem:ControlHandle;                        { Control handle }
  1957.  
  1958.  
  1959. begin
  1960. GetDItem(theDialog,theItem,DType,DItem,tempRect);{ Get the item handle }
  1961. CItem := ControlHandle(DItem);                        { Change dialog handle to control handle }
  1962. SetCtlMin(CItem,min);                                { The Min }
  1963. SetCtlMax(CItem,max);                                { The Max }
  1964. SetCtlValue(CItem,value);                            { The first selection }
  1965. end;
  1966.  
  1967. { ======================================================= }
  1968.  
  1969. procedure SetupPopupMenu(theDialog:DialogPtr;theItem:integer;Enabled:Boolean;theMenuID,value:integer);
  1970. var
  1971.     tempRect:Rect;                                { Temporary rectangle variable }
  1972.     DType:integer;                                { Type of dialog item }
  1973.     DItem:Handle;                                { Handle to the dialog item }
  1974.     CItem:ControlHandle;                        { Control handle }
  1975.  
  1976.  
  1977. begin
  1978. GetDItem(theDialog,theItem,DType,DItem,tempRect);{ Get the item handle }
  1979. CItem := ControlHandle(DItem);                        { Change dialog handle to control handle }
  1980. SizeControl(CItem,tempRect.right - tempRect.left, tempRect.bottom - tempRect.top);{ Size it to the item size }
  1981. SetCtlValue(CItem,value);                            { The first selection }
  1982. SetCtlMax(CItem,theMenuID);                            { The max value is the menu ID }
  1983.  
  1984. if (Enabled) then                                        { See if enable or disable the zone }
  1985.     HiliteControl(CItem,0)                        { Enable the zone }
  1986. else
  1987.     HiliteControl(CItem,255);                        { Dim the zone }
  1988.  
  1989. SetNameForPopup(CItem);                                { Set the popup title }
  1990. ShowControl(CItem);                                    { Show it to activate it }
  1991. end;
  1992.  
  1993. { ======================================================= }
  1994.  
  1995. procedure SetupPalette(theDialog:DialogPtr;theItem:integer;Enabled:Boolean;NumberRows,NumberCols,PalPictureID,HiliteMethod:longint);
  1996. var
  1997.     CItem:ControlHandle;                        { Control handle }
  1998.  
  1999.  
  2000. begin
  2001. BasicSetup(theDialog,theItem,Enabled,0,CItem);
  2002.  
  2003. SetCtlMax(CItem,(NumberRows * $00000100) + NumberCols);    { The max value is the (rows * 0x0100) + columns }
  2004. SetCtlValue(CItem,(1 * $0100) + 1 );                { The current value is the (rows * 0x0100) + columns }
  2005. CItem^^.contrlData := Handle((BOR($FF000000,PalPictureID) + (HiliteMethod * $00010000)));{ Picture ID and hilite method }
  2006. ShowControl(CItem);                                    { Show it to activate it }
  2007. end;
  2008.  
  2009. { ======================================================= }
  2010.  
  2011. procedure SetupIconSicn(theDialog:DialogPtr;theItem:integer;Enabled:Boolean;NormalID,HilitedID:longint);
  2012. var
  2013.     CItem:ControlHandle;                        { Control handle }
  2014.     LTemp:longint;
  2015.  
  2016.  
  2017. begin
  2018. BasicSetup(theDialog,theItem,Enabled,0,CItem);
  2019.  
  2020. LTemp := (NormalID * $00010000) + HilitedID;    
  2021. CItem^^.contrlData := Handle(LTemp);                { Send it }
  2022.  
  2023. SetCtlMax(CItem,12345);                                { Set the flag to the CDEF }
  2024.  
  2025. ShowControl(CItem);                                    { Show it to activate it }
  2026. end;
  2027.  
  2028. { ======================================================= }
  2029.  
  2030. procedure ClearTheRadio(theDialog:DialogPtr;theItem:integer;var value:integer);
  2031. var
  2032.     tempRect:Rect;                                { Temporary rectangle variable }
  2033.     DType:integer;                                { Type of dialog item }
  2034.     DItem:Handle;                                { Handle to the dialog item }
  2035.     CItem:ControlHandle;                        { Control handle }
  2036.  
  2037.  
  2038. begin
  2039. GetDItem(theDialog,theItem,DType,DItem,tempRect);{ Get which item was pressed }
  2040. CItem := ControlHandle(DItem);                        { Change the pointer for getting to the control }
  2041. SetCtlValue(CItem,0);
  2042. value := 0;                                            { Set the current Radio value }
  2043. end;
  2044.  
  2045. { ======================================================= }
  2046.  
  2047. procedure DrawStaticTextBox(ResID:integer;theRect:Rect;Justify,theSize,theFont:integer;theStyle:Style);
  2048. var
  2049.     sTemp:Str255;
  2050.  
  2051.  
  2052. begin
  2053. TextSize(theSize);                            { Set text size }
  2054. TextFont(theFont);                            { Set text font }
  2055. TextFace(theStyle);                            { Set text style }
  2056. GetIndString(sTemp,ResID,1);                { Get the string }
  2057. TextBox(Pointer(ord(@sTemp) + 1),length(sTemp),theRect,Justify);
  2058.  
  2059. TextFont(applFont);                            { Back to the application font }
  2060. TextSize(12);                                { Back to the application size }
  2061. TextFace([]);                                { Set text style }
  2062. end;
  2063.  
  2064. { ======================================================= }
  2065.  
  2066. procedure DrawStaticLine(ResID,Left,Top,theSize,theFont:integer;theStyle:Style);
  2067. var
  2068.     sTemp:Str255;
  2069.  
  2070.  
  2071. begin
  2072. TextSize(theSize);                            { Set text size }
  2073. TextFont(theFont);                            { Set text font }
  2074. TextFace(theStyle);                            { Set text style }
  2075. GetIndString(sTemp,ResID,1);                { Get the string }
  2076. MoveTo(Left,Top + theSize - 3);
  2077. DrawString(sTemp);
  2078.  
  2079. TextFont(applFont);                            { Back to the application font }
  2080. TextSize(12);                                { Back to the application size }
  2081. TextFace([]);                                { Set text style }
  2082. end;
  2083.  
  2084. { ======================================================= }
  2085.  
  2086. procedure DrawTheTEArea(theTERect:Rect;theTE:TEHandle;theSize,theFont:integer;theStyle:Style);
  2087.  
  2088.  
  2089. begin
  2090. TextSize(theSize);                            { Set text size }
  2091. TextFont(theFont);                            { Set text font }
  2092. TextFace(theStyle);                            { Set text style }
  2093. FrameRect(theTERect);                        { Frame this TE area }
  2094. if (theTE <> nil) then
  2095.     TEUpdate(theTERect,theTE);                { Update the TE area }
  2096.  
  2097. TextFont(applFont);                            { Back to the application font }
  2098. TextSize(12);                                { Back to the application size }
  2099. TextFace([]);                                { Set text style }
  2100. end;
  2101.  
  2102. { ======================================================= }
  2103.  
  2104. function MakeNormalControl(theWindow:WindowPtr;theResID:integer;Enabled:Boolean;InitialValue:integer):ControlHandle;
  2105. var
  2106.     theCtrl:ControlHandle;
  2107.  
  2108.  
  2109. begin
  2110. theCtrl := GetNewControl(theResID,theWindow);    { Make a new control }
  2111. SetCtlValue(theCtrl,InitialValue);                { Set the value }
  2112. if (Enabled) then
  2113.     HiliteControl(theCtrl,0)                    { Enable the control }
  2114. else
  2115.     HiliteControl(theCtrl,255);                    { Disable the control }
  2116.  
  2117. MakeNormalControl := theCtrl;
  2118. end;
  2119.  
  2120. { ======================================================= }
  2121.  
  2122. function MakeTheHotSpot(theWindow:WindowPtr;theResID:integer;MakeHotSpot:Boolean;LineWidth,ShadowWidth:longint;
  2123.     MessageResID:integer;Enabled:Boolean):ControlHandle;
  2124. var
  2125.     theCtrl:ControlHandle;
  2126.     LTemp:longint;
  2127.     sTemp:Str255;
  2128.  
  2129.  
  2130. begin
  2131. theCtrl := GetNewControl(theResID,theWindow);    { Make a new control }
  2132. HideControl(theCtrl);                            { Hide till we set all the parameters }
  2133.  
  2134. if (Enabled) then
  2135.     HiliteControl(theCtrl,0)                    { Enable the control }
  2136. else
  2137.     HiliteControl(theCtrl,255);                    { Disable the control }
  2138.  
  2139. if (MakeHotSpot) then
  2140.     LTemp := $00FF0000                            { Tell the CDEF that it is a HotSpot }
  2141. else
  2142.     LTemp := $00000000;                            { Tell the CDEF that it is a Rectangle }
  2143.  
  2144. LTemp := LTemp + (BAND($000000FF,LineWidth) * $00000100);    { Set the line width }
  2145. LTemp := LTemp + BAND($000000FF,ShadowWidth);        { Set the shadow width }
  2146.  
  2147. if (MessageResID <> 0) then
  2148.     begin
  2149.     LTemp := LTemp + $01000000;
  2150.     GetIndString(sTemp,MessageResID,1);            { Get the string }
  2151.     SetCTitle(theCtrl,sTemp);                    { Set the string }
  2152.     end;
  2153.  
  2154. theCtrl^^.contrlData := Handle(LTemp);            { Send it }
  2155.  
  2156. SetCtlValue(theCtrl,0);
  2157. ShowControl(theCtrl);                            { Show it to activate it }
  2158.  
  2159. MakeTheHotSpot := theCtrl;
  2160. end;
  2161.  
  2162. { ======================================================= }
  2163.  
  2164. function MakeIconSicn(theWindow:WindowPtr;theResID:integer;Enabled:Boolean;NormalID,HilitedID:longint):ControlHandle;
  2165. var
  2166.     theCtrl:ControlHandle;
  2167.  
  2168.  
  2169. begin
  2170. theCtrl := GetNewControl(theResID,theWindow);    { Make a new button }
  2171. if (Enabled) then
  2172.     HiliteControl(theCtrl,0)                    { Enable the button }
  2173. else
  2174.     HiliteControl(theCtrl,255);                    { Disable the button }
  2175. theCtrl^^.contrlData := Handle(((NormalID * $00010000) + HilitedID));    { Set the icons to be used }
  2176.  
  2177. MakeIconSicn := theCtrl;
  2178. end;
  2179.  
  2180. { ======================================================= }
  2181.  
  2182. function MakePlugin(theWindow:WindowPtr;theResID:integer;Enabled:Boolean;
  2183.     NormalID,HilitedID:longint;MessageResID,InitialValue:integer):ControlHandle;
  2184. var
  2185.     theCtrl:ControlHandle;
  2186.     LTemp:longint;
  2187.     sTemp:Str255;
  2188.  
  2189.  
  2190. begin
  2191. theCtrl := GetNewControl(theResID,theWindow);    { Make a new button }
  2192. HideControl(theCtrl);
  2193. if (Enabled) then
  2194.     HiliteControl(theCtrl,0)                    { Enable the button }
  2195. else
  2196.     HiliteControl(theCtrl,255);                    { Disable the button }
  2197.  
  2198. LTemp := (HilitedID * $00010000) + NormalID;    
  2199. theCtrl^^.contrlData := Handle(LTemp);            { Send it }
  2200.  
  2201. SetCtlMax(theCtrl,12345);                        { Set the flag to the CDEF }
  2202.  
  2203. if (MessageResID <> 0) then
  2204.     begin
  2205.     GetIndString(sTemp,MessageResID,1);            { Get the string }
  2206.     SetCTitle(theCtrl,sTemp);                    { Set the string }
  2207.     end;
  2208.  
  2209. SetCtlValue(theCtrl,InitialValue);
  2210. ShowControl(theCtrl);                            { Show it to activate it }
  2211.  
  2212. MakePlugin := theCtrl;
  2213. end;
  2214.  
  2215. { ======================================================= }
  2216.  
  2217. procedure MakeMinMaxValue(theControl:ControlHandle;min,max,value:integer);
  2218.  
  2219.  
  2220. begin
  2221. SetCtlMin(theControl,min);                                { The Min }
  2222. SetCtlMax(theControl,max);                                { The Max }
  2223. SetCtlValue(theControl,value);                            { The first selection }
  2224. end;
  2225.  
  2226. { ======================================================= }
  2227.  
  2228. function MakePopupMenu(theWindow:WindowPtr;theResID:integer;Enabled:Boolean;theMenuID,value:integer):ControlHandle;
  2229. var
  2230.     theCtrl:ControlHandle;
  2231.     LTemp:longint;
  2232.     sTemp:Str255;
  2233.  
  2234.  
  2235. begin
  2236. theCtrl := GetNewControl(theResID,theWindow);    { Make a new button }
  2237. HideControl(theCtrl);
  2238. if (Enabled) then
  2239.     HiliteControl(theCtrl,0)                    { Enable the button }
  2240. else
  2241.     HiliteControl(theCtrl,255);                    { Disable the button }
  2242.  
  2243. SetCtlMax(theCtrl,theMenuID);                    { Set the menu for the CDEF }
  2244.  
  2245. SetCtlValue(theCtrl,value);
  2246. SetNameForPopup(theCtrl);                        { Set the popup title }
  2247. ShowControl(theCtrl);                            { Show it to activate it }
  2248.  
  2249. MakePopupMenu := theCtrl;
  2250. end;
  2251.  
  2252. { ======================================================= }
  2253.  
  2254. procedure UpdateTheList(theRgn:RgnHandle;theList:ListHandle;theRect:Rect;theSize,theFont:integer;
  2255.     theStyle:Style;InDialog:Boolean);
  2256. var
  2257.     tempRect:Rect;
  2258.  
  2259.  
  2260. begin
  2261. TextSize(theSize);                            { Set text size }
  2262. TextFont(theFont);                            { Set text font }
  2263. TextFace(theStyle);                            { Set text style }
  2264.  
  2265. LUpdate(theRgn,theList);                    { Update this list }
  2266. tempRect := theRect;                        { Start with full size }
  2267. InsetRect(tempRect, -1, -1);                { Set for framing }
  2268. FrameRect(tempRect);                        { Frame it }
  2269.  
  2270. if (InDialog) then
  2271.     TextFont(systemFont)                    { Back to the system font }
  2272. else
  2273.     TextFont(applFont);                        { Back to the application font }
  2274. TextSize(12);                                { Back to the application size }
  2275. TextFace([]);                                { Set text style }
  2276. end;
  2277.  
  2278. { ======================================================= }
  2279.  
  2280. procedure ClickInTheList(myPt:Point;modifiers:integer;theList:ListHandle;theSize,theFont:integer;
  2281.     theStyle:Style;InDialog:Boolean);
  2282. var
  2283.     DoubleClick:Boolean;
  2284.  
  2285.  
  2286. begin
  2287. TextSize(theSize);                            { Set text size }
  2288. TextFont(theFont);                            { Set text font }
  2289. TextFace(theStyle);                            { Set text style }
  2290.  
  2291. DoubleClick := LClick(myPt,modifiers,theList);
  2292.  
  2293. if (InDialog) then
  2294.     TextFont(systemFont)                    { Back to the system font }
  2295. else
  2296.     TextFont(applFont);                        { Back to the application font }
  2297. TextSize(12);                                { Back to the application size }
  2298. TextFace([]);                                { Set text style }
  2299. end;
  2300.  
  2301. { ======================================================= }
  2302.  
  2303. function MakePalette(theWindow:WindowPtr;theResID:integer;Enabled:Boolean;
  2304.     NumberRows,NumberCols,PalPictureID,HiliteMethod:longint):ControlHandle;
  2305. var
  2306.     theCtrl:ControlHandle;
  2307.     LTemp:longint;
  2308.  
  2309.  
  2310. begin
  2311. theCtrl := GetNewControl(theResID,theWindow);    { Make a new button }
  2312. HideControl(theCtrl);
  2313. if (Enabled) then
  2314.     HiliteControl(theCtrl,0)                    { Enable the button }
  2315. else
  2316.     HiliteControl(theCtrl,255);                    { Disable the button }
  2317.  
  2318. SetCtlMax(theCtrl,(NumberRows * $00000100) + NumberCols);    { The max value is the (rows * $0100) + columns }
  2319. SetCtlValue(theCtrl,(1 * $0100) + 1 );                { The current value is the (rows * $0100) + columns }
  2320. theCtrl^^.contrlData := Handle((BOR($FF000000,PalPictureID) + (HiliteMethod * $00010000)));{ Picture ID and hilite method }
  2321.  
  2322. ShowControl(theCtrl);                            { Show it to activate it }
  2323.  
  2324. MakePalette := theCtrl;
  2325. end;
  2326.  
  2327. { ======================================================= }
  2328.  
  2329. procedure Activate_TE_Area(InDialog:Boolean;myPt:Point;theTE:TEHandle;thetextSize,thetextFont:integer;textStyle:Style);
  2330.  
  2331.  
  2332. begin
  2333. TextSize(thetextSize);                            { Set text size }
  2334. TextFont(thetextFont);                            { Set text font }
  2335. TextFace(textStyle);                        { Set text style }
  2336. if (theInput <> nil) then                    { See if there is already a TE area }
  2337.     TEDeactivate(theInput);                    { ...Yes,so turn it off }
  2338.  
  2339. theInput := theTE;
  2340. TEActivate(theInput);                        { Turn it on }
  2341. TEClick(myPt,false,theInput);
  2342. if (InDialog) then
  2343.     TextFont(systemFont)                    { Back to the system font }
  2344. else
  2345.     TextFont(applFont);                        { Back to the application font }
  2346. TextSize(12);
  2347. TextFace([]);
  2348. end;
  2349.  
  2350. { ======================================================= }
  2351. { ======================================================= }
  2352. end.
  2353.